我有以下xml:
Biscuits Wrapped
Finished
Biscuits
Biscuits (Wrapped)
Biscuits Sweet
Finished
Biscuits
Biscuits (Sweets)
Biscuits Savoury
Finished
Biscuits
Biscuits For Cheese
....
我已使用以下代码将其加载到树中:try:
groups = etree.parse(PRODUCT_GROUPS_XML_FILEPATH)
root = groups.getroot()
internalGroup = root.findall("./internal-code")
LOG.append("[INFO] product groupings file loaded and parsed ok")
except Exception as e:
LOG.append("[ERROR] PRODUCT GROUPINGS XML FILE ACCESS PROBLEM")
LOG.append("[***TERMINATED***]")
writelog()
exit()
我想使用XPath找到正确的,然后能够访问该组的子节点。因此,如果我正在搜索内部代码221并想要网络类别,我将执行以下操作:internalGroup.find("internal-code", 221).get("web-category").text
我对XML和Python没有经验,我已经盯着它看了很久了。所有的帮助都得到了非常感激的接待。谢谢