How to read in xml header/version using python

2019-08-07 14:16发布

问题:

I'm looking for a way to read in the XML version header using the xml.sax parser in python.

**<?xml version="1.0"?>**
<root>
  <child>Hello</child>
  <child2>World</child>
</root>

So far, whenever I try to read in the XML, it just seems to skip over the header and go to the root node.

Any help would be greatly appreciated.

Thank you.

回答1:

I am not sure if this is available in your version of SAX, but the way to get it would be through the Locator2.

http://sax.sourceforge.net/apidoc/org/xml/sax/ext/Locator2.html



标签: python xml sax