擅长:python、mysql、java
<p>不清楚您到底想访问什么,但请尝试以下方法:</p>
<pre><code>from lxml import etree
doc=etree.parse( xmlfile )
ns={'dc': 'http://purl.org/dc/elements/1.1/',
'oai': 'http://www.openarchives.org/OAI/2.0/'}
doc.xpath( '//dc:subject' , namespaces=ns ) # get all of the dc:subjects
doc.xpath( '//dc:*', namespaces=ns ) # get all elements in dc: namespace
# more specific path
doc.xpath( '/oai:OAI-PMH/oai:ListRecords/oai:record/oai:metadata/*/dc:*', namespaces=ns )
x=doc.xpath( '/oai:OAI-PMH/oai:ListRecords/oai:record/oai:metadata/*' )
x[0].xpath( '*[contains(.,"Geo")]' ) # you can also call xpath from non document nodes
x[0].xpath( 'dc:subject/text()' , namespaces=ns ) # get the text of dc:subjects
</code></pre>
<p>在python或lxml文档之外阅读一些关于xpath的文档。
它们告诉您如何在python中使用xpath,但实际上并不是xpath教程。在</p>
<p>注意find()、findall()方法采用<a href="http://lxml.de/tutorial.html#elementpath" rel="nofollow">ElementPaths</a>,这是一种
类xpath表达式的有限子集。在</p>