tree.docinfo.xml_version
tree.docinfo.encoding
tree.docinfo.standalone
tree.docinfo.root_name
tree.getroot().prefix 
Get some information from the XML document using lxml
General
XML
LXML

obtains the document information from any XML file

Description :

Example :
# Version of the XML, not the file formats version
tree.docinfo.xml_version
# Character Encoding (e.g. UTF-8)
tree.docinfo.encoding
# The value of Standalone flag
tree.docinfo.standalone
# Name of the root node
tree.docinfo.root_name
# the root node's namespace prefix
tree.xpath("/*")[0].prefix
# the root node's namespace prefix
tree.getroot().prefix
# get the URI/URL of the given prefix
tree.xpath("/*")[0].nsmap.get(prefix_of_root)
# get the URI/URL of the given prefix
tree.getroot().nsmap.get(prefix_of_root)
2025 Jan