validating XML
andrea crotti
andrea.crotti.0 at gmail.com
Wed Jun 13 11:45:20 EDT 2012
So as far as I understood what I should do is the following.
Go through my own XML keeping track of the full path of everything for
example
<SETUP>
<SETUP/COMMENT>
<SETUP/OTHER>
and so on, then for every entry found in this iteration, check the schema
to make sure that that particular construct is allowed
on that level of the tree.
I have something like this for example that creates a dictionary from an
element tree element...
Does it make sense or am I going in the wrong direction?
def etree_to_dict(xml_file):
"""Takes the root node from the XML and generates a dictionary
"""
dic = {}
etree = ElementTree.parse(open(xml_file))
root = list(etree.iter())[0]
queue = [root]
while queue:
el = queue.pop()
childs = el.getchildren()
queue += childs
dic[el] = childs
return dic
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120613/a37f8aae/attachment.html>
More information about the Python-list
mailing list