![](/img/trans.png)
[英]How to conditionally insert an attribute into a node in Python using xml.etree.ElementTree
[英]xml.etree.ElementTree: How to access node with attribute name using python
需要幫助來查找特定的“xsd:complexType name='Fort'”
我試過了:
for a in root.findall('xsd:complexType name= 'Fort''):
print(a.attrib)
上面的代碼不起作用
下面是xml:
<xsd:complexType name="Fort">
<xsd:sequence>
<xsd:element name="register" type="Skipsregister" />
<xsd:element name="type" type="pstype" />
<xsd:element name="om" type="aade" />
</xsd:sequence>
</xsd:complexType>
來自xml.etree.ElementTree Docs :我們初始化一棵樹,然后通過 tree.getroot() 獲取根。
然后你可以這樣做:
for child in root:
if(child.attrib == "Fort"): #or child.tag, depending on what you mean by attribute
#do whatever you want here
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.