I'm trying to specify a namespace using lxml similar to this example (taken from here):
<TreeInventory xsi:noNamespaceSchemaLocation="Trees.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">">
</TreeInventory>
I'm not sure how to add the Schema instance to use and also the Schema location. The documentation got me started, by doing something like:
>>> NS = 'http://www.w3.org/2001/XMLSchema-instance'
>>> TREE = '{%s}' % NS
>>> NSMAP = {None: NS}
>>> tree = etree.Element(TREE + 'TreeInventory', nsmap=NSMAP)
>>> etree.tostring(tree, pretty_print=True)
'<TreeInventory xmlns="http://www.w3.org/2001/XMLSchema-instance"/>\n'
I'm not sure how to specify it an instance though, and then also specify a location. It seems like this can be done with the nsmap
keyword-arg in etree.Element
, but I don't see how.