Unable to round trip a document generated with pyxb
ar = ocibase.BroadsoftDocument(protocol="OCI", sessionId='d3cafbad', command=[bwas.AuthenticationRequest(userId='someuserID'),])
ar.toxml()
u'<?xml version="1.0" ?><ns1:BroadsoftDocument protocol="OCI" xmlns:ns1="C" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><sessionId>d3cafbad</sessionId><command xsi:type="AuthenticationRequest"><userId>someuserID</userId></command></ns1:BroadsoftDocument>'
bd = ocibase.CreateFromDocument(ar.toxml())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "ocibase.py", line 32, in CreateFromDocumentsaxer.parse(StringIO.StringIO(xml_text))
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xml/sax/expatreader.py", line 107, in parse
xmlreader.IncrementalParser.parse(self, source)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xml/sax/xmlreader.py", line 123, in parse
self.feed(buffer)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xml/sax/expatreader.py", line 207, in feed
self._parser.Parse(data, isFinal)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xml/sax/expatreader.py", line 338, in start_element_ns
AttributesNSImpl(newattrs, qnames))
File "/Library/Python/2.6/site-packages/PyXB-1.1.3-py2.6.egg/pyxb/binding/saxer.py", line 329, in startElementNS
(did_replace, type_class) = XSI._InterpretTypeAttribute(attrs.getValue(self.XSITypeTuple), ns_ctx, None, type_class)
File "/Library/Python/2.6/site-packages/PyXB-1.1.3-py2.6.egg/pyxb/namespace/builtin.py", line 103, in _InterpretTypeAttribute
type_en = ns_ctx.interpretQName(type_name, namespace=fallback_namespace)
File "/Library/Python/2.6/site-packages/PyXB-1.1.3-py2.6.egg/pyxb/namespace/resolution.py", line 611, in interpretQName
raise pyxb.SchemaValidationError('QName %s with absent default namespace cannot be resolved' % (local_name,))
pyxb.exceptions_.SchemaValidationError: QName AuthenticationRequest with absent default namespace cannot be resolved
required schema and generated source
PyXB is correct here.
AuthenticationRequest is defined in OCISchemaLogin.xsd, which has an absent namespace. It must be found within the context of bwas.Namespace.
When you create the document using the ocibase module, which contains material in namespace "C", there is no way for PyXB to know how to resolve symbols that are in an absent namespace, as there is no way (in XML) to associate those symbols with a namespace.
If, instead, you create the document with:
so the fallback namespace to use when resolving symbols in an absent namespace is bwas.Namespace, things work as they should.
(Arguably, the definition of CreateFromDocument at the top of each module is wrong, since it provides a keyword argument default_namespace which if it wasn't ignored might have allowed you to do:
However, some thought and testing of existing practice must be directed to whether this is the intent of that keyword, or whether it should be renamed to fallback_namespace, which is the keyword normally used for that function.)
So... the round trip works when using
But when starting the conversation with Broadsoft it fails when using bwas.CreateFromDocument
AuthenticationResponse returned from server
Where am I going wrong with this?
You're not going wrong. Here the issue is that the outermost element defines a default namespace "C", which discards the normal fallback. PyXB is not interpreting the internal set of an empty default namespace as being the fallback namespace; probably because that deep inside processing it doesn't know which absent namespace to select.
I expect this will turn out to be a PyXB issue, but I'll have to dig into this tomorrow.
patch for trac #119
Fixed in the trac0119.patch attachment and pushed to the next branch for the next release. (You do still have to use the module corresponding to the absent namespace to do the parsing.)
Verified initial test succeeds!
Thank you!