Unfortunately, minidom you from omitting the XML Declaration.
But you can always serialize the contents of the document yourself by calling toxml() on the root element of the document instead of document . Then you will not get the XML declaration:
xml= document.documentElement.toxml('utf-8')
... but then you also won’t get anything else outside the root element, such as DOCTYPE, or any comments or processing instructions. If you need it, serialize each child of the document one by one:
xml= '\n'.join(node.toxml('utf-8') for node in document.childNodes)
I wondered if there are any other packages that let you neglect the header.
DOM Level 3 LS defines an xml-declaration config parameter that you can use to suppress it. The only Python implementation I know of is pxdom , which is fully standards compliant, but not very fast.
bobince
source share