<ManagedElement xmlns="urn:params:xml:ManagedElement">
<moId>1386546</moId>
<mimType>PNF</mimType>
<productType>2</productType>
<autoGetGeographicPos>1</autoGetGeographicPos>
<sharedDeviceEnvParaSwitch>1</sharedDeviceEnvParaSwitch>
<rfSwmMsConfig>1</rfSwmMsConfig>
</ManagedElement>
try:
import xml.etree.cElementTree as ET
except ImportError:
import xml.etree.ElementTree as ET
import pandas as pd
tree = ET.parse("rem_old.xml")
root = tree.getroot()
for child in root:
print(child.tag)
{urn:params:xml:ManagedElement}moId
{urn:params:xml:ManagedElement}mimType
{urn:params:xml:ManagedElement}productType
{urn:params:xml:ManagedElement}autoGetGeographicPos
{urn:params:xml:ManagedElement}sharedDeviceEnvParaSwitch
{urn:params:xml:ManagedElement}rfSwmMsConfig
使用root.find('moId')无结果,只能是root.find('{urn:params:xml:ManagedElement}moId')
为什么显示标签会带根元素属性
moId
mimType
productType
autoGetGeographicPos
sharedDeviceEnvParaSwitch
rfSwmMsConfig
#可以把花口号前的内容截掉
print(child.tag[child.tag.find('}')+1:])