7
我有一些XML是通過lxml在python中解析的。如何測試某個屬性中是否存在某個XML
我遇到了一些元素有屬性而有些元素沒有的情況。
我需要提取它們,如果它們存在,但跳過他們,如果他們不這樣做 - 我目前有錯誤着陸(因爲我的做法是錯誤的...)
我已經部署了testfornull,但這並不適用於所有情況:
代碼:
if root[0][a][b].attrib == '<>':
ByteSeqReference = "NULL"
else:
ByteSeqReference = (attributes["Reference"])
XML答:
<ByteSequence Reference="BOFoffset">
XML B:
<ByteSequence Endianness = "little-endian" Reference="BOFoffset">
XML C:
<ByteSequence Endianness = "little-endian">
XML d:
<ByteSequence>
我當前方法只能與A,B或D.它處理不能使用C應付
唉唉。這是如何工作的。 (我也很驚訝......)。感謝您的時間,我很感激。這完全解決了它。 – Jay 2012-04-11 23:32:39