I am trying to create shibboleth configuration files using xml.etree in python and I am having problems with its lack of namespace assignments when outputting a finished document. I am sure this is the problem described in Outputting an โUnusedโ XML Namespace Using ElementTree
I announce them ...
namespaces = {
'resolver': 'urn:mace:shibboleth:2.0:resolver',
'xsi': 'http://www.w3.org/2001/XMLSchema-instance',
'pc': 'urn:mace:shibboleth:2.0:resolver:pc',
'ad': 'urn:mace:shibboleth:2.0:resolver:ad',
'dc': 'urn:mace:shibboleth:2.0:resolver:dc',
'enc': 'urn:mace:shibboleth:2.0:attribute:encoder',
'sec': 'urn:mace:shibboleth:2.0:security',
}
for prefix, uri in namespaces.iteritems():
ET.register_namespace(prefix, uri)
If I print the namespaces that were defined for the document ...
print json.dumps( ET._namespace_map, indent=True )
I see my namespaces there.
{
"urn:mace:shibboleth:2.0:resolver:pc": "pc",
"http://schemas.xmlsoap.org/wsdl/": "wsdl",
"urn:mace:shibboleth:2.0:resolver:ad": "ad",
"urn:mace:shibboleth:2.0:resolver": "resolver",
"http://www.w3.org/1999/xhtml": "html",
"http://www.w3.org/1999/02/22-rdf-syntax-ns#": "rdf",
"urn:mace:shibboleth:2.0:security": "sec",
"urn:mace:shibboleth:2.0:attribute:encoder": "enc",
"http://www.w3.org/2001/XMLSchema": "xs",
"http://www.w3.org/2001/XMLSchema-instance": "xsi",
"http://www.w3.org/XML/1998/namespace": "xml",
"urn:mace:shibboleth:2.0:resolver:dc": "dc"
}
stdout, "enc" "pc". , "enc" "pc" , . , ...
root.set("xmlns:enc", "urn:mace:shibboleth:2.0:attribute:encoder")
root.set("xmlns:pc", "urn:mace:shibboleth:2.0:resolver:pc")
, .
xml.etree ?