1
如何有選擇地讀取下面的xml,以便在遇到具有相似名稱的標籤時,xml讀取器會跳過第一個標籤。如何選擇性讀取xml文件
<paraphrase_candidates source_description="id:9249">
<annotation author="87" is_paraphrase="true" source_description="id:18689" >
<phenomenon type="lex_same_polarity" projection="local" source_description="id:5528">
<snippet id="16488" >
<scope offset="125" length="4"/>
</snippet>
<snippet id="16489" >
<scope offset="71" length="11"/>
</snippet>
</phenomenon>
<phenomenon type="syn_diathesis" source_description="id:5536">
<snippet id="16488" >
<scope offset="32" length="92"/>
</snippet>
<scope offset="0" length="70"/>
</phenomenon>
</annotation>
</paraphrase_candidates>
具體而言,我想跳過第一現象標籤和檢索第二現象標籤的範圍屬性。
My attempts
for x in root.findall('scope'):
print x.attrib[0]
輸出:空
預期輸出:{offset="32" length="92"} and {offset="0" length="70}
感謝您的解決方案,它運行良好。 – Boby
如果xml文件的前面有一個http,那麼它如何工作? '' –
Boby
@Boby,搜索」xpath默認命名空間「。它不稱爲「一個http」,它被稱爲命名空間。請不要用評論來提問後續問題:提出一個新問題。哦,如果答案有效,你應該接受它(點擊勾號)。 –