In a way, you need to include "xs": SCHEMA_NAMESPACEone in your NSMAP, otherwise nothing in your generated XML will actually display the xs prefix to fix the namespace. It will also allow you to simply specify the names of your elements using prefixes; eg. "Xs: element"
, , , , , , , NSMAP. XML , , :
NSMAP "xs" ;_Element.nsmap , .
:
SCHEMA_NAMESPACE = "http://www.w3.org/2001/XMLSchema"
def add_element(schema):
nsmap = schema.nsmap
nsrmap = dict([(uri, prefix) for prefix, uri in nsmap.items()])
prefix = nsrmap[SCHEMA_NAMESPACE]
xs = lambda name: "%s:%s" % (prefix, name)
element = schema.makeelement(xs("element"), nsmap=nsmap,
attrib={'name': 'age', 'type': xs('string')})
schema.append(element)
return etree.tostring(schema, pretty_print=True)
.