【发布时间】:2015-05-18 14:05:39
【问题描述】:
我有一个xml文件作为文本文件,如下:-
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE dblp SYSTEM "dblp.dtd">
<dblp>
<article mdate="2011-01-11" key="journals/acta/Saxena96">
<author>Sanjeev Saxena</author>
<title>Parallel Integer Sorting and Simulation Amongst CRCW Models.</title>
<pages>607-619</pages>
<year>1996</year>
<volume>33</volume>
<journal>Acta Inf.</journal>
<number>7</number>
<url>db/journals/acta/acta33.html#Saxena96</url>
<ee>http://dx.doi.org/10.1007/BF03036466</ee>
</article>
<article mdate="2011-01-11" key="journals/acta/Simon83">
<author>Hans-Ulrich Simon</author>
<title>Pattern Matching in Trees and Nets.</title>
<pages>227-248</pages>
<year>1983</year>
<volume>20</volume>
<journal>Acta Inf.</journal>
<url>db/journals/acta/acta20.html#Simon83</url>
<ee>http://dx.doi.org/10.1007/BF01257084</ee>
</article>
如果我输入'Parallel',那么我应该获得整个标题名称,后跟'author','pages','year','volume','journal'
作为示例输出:-
Sanjeev Saxena
Parallel Integer Sorting and Simulation Amongst CRCW Models.
607-619
1996
33
Acta Inf.
如何使用正则表达式执行上述操作?请帮忙!
提前致谢!
【问题讨论】:
-
请read this answer - 它也适用于 XML。对于 Python,您可以使用
lxml、BeautifulSoup 4 (bs4) 或来自 the standard library 的任何内容
标签: python regex xml xml-parsing