我正在使用 ElementTree 解析下面显示的 xml,但出现Invalid Predicate
代码错误。
基本上我试图找到connect
具有特定pin
属性名称的元素。
XML
<deviceset>
<devices>
<device name="">
<connects>
<connect gate="G$1" pin="+15V_DC" pad="7"/>
<connect gate="G$1" pin="FB" pad="3"/>
<connect gate="G$1" pin="ICOM" pad="4"/>
<connect gate="G$1" pin="IN+" pad="5"/>
<connect gate="G$1" pin="IN-" pad="6"/>
<connect gate="G$1" pin="OUT_HI" pad="1"/>
<connect gate="G$1" pin="OUT_LO" pad="9"/>
<connect gate="G$1" pin="PWRCOM" pad="2"/>
</connects>
</device>
</devices>
</deviceset>
蟒蛇代码
# Imports
import xml.etree as ET
from xml.etree.ElementTree import Element, SubElement, Comment, tostring
# Open a file sent to the function
file = open(os.path.join(__location__, file));
tree = ET.parse(file)
root = tree.getroot()
deviceset = root.find ('deviceset')
deviceset.find('devices').find('device').find('connects').**findall("./connect[@pin = \"FB\"]")**
问题似乎是 XPATH 样式路径(上面突出显示)。
关于我做错了什么的任何想法?