Print all xml child node using python

后端 未结 2 687
小蘑菇
小蘑菇 2021-01-24 09:07

I want to print all the values of the \"ClCompiler\" child of \"ItemGroup\" of my xml file.

my python code

tree = minidom.parse(project_path)
itemgroup         


        
2条回答
  •  半阙折子戏
    2021-01-24 09:29

    An alternate solution using ElementTree,

    import xml.etree.ElementTree as ET
    root = ET.fromstring('''\
    
    
    
    
    
    
    ''')
    
    for child in root.iter('ClCompile'):
        print ET.tostring(child)
    

    While parsing from file,

    import xml.etree.ElementTree as ET
    tree=ET.parse('text.xml')
    root = tree.getroot()
    for child in root.iter('ClCompile'):
        print ET.tostring(child)
    

提交回复
热议问题