给定以下xml:
<language>en-US</language>
<provider>VenturesLLC</provider>
<video>
<original_spoken_locale>en-US</original_spoken_locale>
<vendor_offer_code>TEST_VENDOR</vendor_offer_code>
<release_date>2011-01-15</release_date>
<title>Moving Forward</title>
<vendor_id>ASDF_ING_2012</vendor_id>
</video>
我正在寻找检索整个 <video>
块。但是,当我这样做时:
>>> f=open('metadata.xml')
>>> contents=f.read()
>>> node=etree.fromstring(contents)
>>> node.xpath("//*[local-name()='video']")[0].text
'\n
请注意,如果我做了类似的事情,node.xpath("//*[local-name()='original_spoken_locale']")[0].text
我会得到正确的'en-US'
. 我将如何提取这个完整的文本以便我可以得到:
text = """
<video>
<original_spoken_locale>en-US</original_spoken_locale>
<vendor_offer_code>TEST_VENDOR</vendor_offer_code>
<release_date>2011-01-15</release_date>
<title>Moving Forward</title>
<vendor_id>ASDF_ING_2012</vendor_id>
</video>"""