Skip to content

Latest commit

 

History

History
25 lines (21 loc) · 1.18 KB

File metadata and controls

25 lines (21 loc) · 1.18 KB

XPath

Python

💡 xmltodict.parse is much easier when no editing is needed

xml.etree.ElementTree.register_namespace works for serialization only. For "find*" methods use namespaces parameter.

import xml.etree.ElementTree
xmlData = xml.etree.ElementTree.parse("autounattend.xml")
namespaces = {"unattend": "urn:schemas-microsoft-com:unattend"}
xmlData.find("./unattend:settings[@pass='windowsPE']/"
        "unattend:component[@name='Microsoft-Windows-International-Core-WinPE']", namespaces=namespaces).items()
xmlData.find("./unattend:settings[@pass='windowsPE']/"
        "unattend:component[@name='Microsoft-Windows-International-Core-WinPE']", namespaces=namespaces).getchildren()

# Unnamed namespaces
dvdImages = xmlData.find('{http://www.virtualbox.org/}Machine/{http://www.virtualbox.org/}MediaRegistry/{http://www.virtualbox.org/}DVDImages')
for image in dvdImages:
    dvdImages.remove(image)