我有以下xml文件
<?xml version="1.0" ?>
<host xmlns="urn:jboss:domain:4.1">
<extensions>
<extension module="org.jboss.as.jmx"/>
</extensions>
<management>
<security-realms>
<security-realm name="ManagementRealm">
<server-identities>
<secret value="c2xhdmVfdXNlcl9wYXNzd29yZA=="/>
</server-identities>
</security-realm>
</security-realms>
</management>
</host>
我正在尝试在 server-identities
下再添加一个标记,如下所示:
import xml.etree.ElementTree as etree
tree = etree.parse(host_slave)
for elements in tree.iter():
if elements.tag == "server-identities":
print "Element tag:{}".format(elements.tag)
print "Elements attribute:{}".format(elements.attrib)
print "\n\n\n"
**add-another-element-here**
这将返回一个空响应,指示条件是否失败。
当我通过删除if
条件迭代所有元素时,我得到以下内容:
Element tag:{urn:jboss:domain:4.1}server-identities
Elements attribute:{}
Element tag:{urn:jboss:domain:4.1}secret
Elements attribute:{'value': 'c2xhdmVfdXNlcl9wYXNzd29yZA=='}
我也试过
if elements.tag == "{urn:jboss:domain:4.1}server-identities"
这给了我同样的空洞反应。
我在这里缺少什么?