0
我正在Dynamo中使用IronPython 2.7。我需要檢查一個節點是否存在。如果是這樣,節點中的文本應該寫入一個列表。如果不是,則應將False寫入列表。檢查節點是否存在
我沒有得到任何錯誤。但是,即使列表中存在節點,它也不會將該文本寫入列表中。 False被正確寫入列表中。
簡單的例子:
<note>
<note2>
<yolo>
<to>
<type>
<game>
<name>Jani</name>
<lvl>111111</lvl>
<fun>2222222</fun>
</game>
</type>
</to>
<mo>
<type>
<game>
<name>Bani</name>
<fun>44444444</fun>
</game>
</type>
</mo>
</yolo>
</note2>
</note>
所以,節點lvl
僅在第一節點game
。我期望得到的結果列表如list[11111, false]
。
這裏是我的代碼:
import clr
import sys
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
sys.path.append("C:\Program Files (x86)\IronPython 2.7\Lib")
import xml.etree.ElementTree as ET
xml="note.xml"
main_xpath=".//game"
searchforxpath =".//lvl"
list=[]
tree = ET.parse(xml)
root = tree.getroot()
main_match = root.findall(main_xpath)
for elem in main_match:
if elem.find(searchforxpath) is not None:
list.append(elem.text)
else:
list.append(False)
print list
爲什麼是空表,其中字符串應該是什麼?我得到list[ ,false]
。
THX對您有所幫助!這正是我需要的:) – Yuli