Using Word 2013, I created a very simple .docx. I extracted the .docx, and attempted to load word/document.xml
using the binding classes I generated using pyxbgen
from the transitional schema files. This causes pyxb to raise UnrecognizedAttributeError
apparently due to the mc:Ignorable
attribute on the document
element:
<w:document xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" mc:Ignorable="w14 w15 wp14">
----> 1 result = w.CreateFromDocument(data)
/home/kyle/dev/pydocx/transitional/w.pyc in CreateFromDocument(xml_text, default_namespace, location_base)
60 if isinstance(xmld, _six.text_type):
61 xmld = xmld.encode(pyxb._InputEncoding)
---> 62 saxer.parse(io.BytesIO(xmld))
63 instance = handler.rootObject()
64 return instance
/home/kyle/.pyenv/versions/2.7.6/lib/python2.7/xml/sax/expatreader.pyc in parse(self, source)
105 self.reset()
106 self._cont_handler.setDocumentLocator(ExpatLocator(self))
--> 107 xmlreader.IncrementalParser.parse(self, source)
108
109 def prepareParser(self, source):
/home/kyle/.pyenv/versions/2.7.6/lib/python2.7/xml/sax/xmlreader.pyc in parse(self, source)
121 buffer = file.read(self._bufsize)
122 while buffer != "":
--> 123 self.feed(buffer)
124 buffer = file.read(self._bufsize)
125 self.close()
/home/kyle/.pyenv/versions/2.7.6/lib/python2.7/xml/sax/expatreader.pyc in feed(self, data, isFinal)
208 # document. When feeding chunks, they are not normally final -
209 # except when invoked from close.
--> 210 self._parser.Parse(data, isFinal)
211 except expat.error, e:
212 exc = SAXParseException(expat.ErrorString(e.code), e, self)
/home/kyle/.pyenv/versions/2.7.6/lib/python2.7/xml/sax/expatreader.pyc in start_element_ns(self, name, attrs)
339
340 self._cont_handler.startElementNS(pair, None,
--> 341 AttributesNSImpl(newattrs, qnames))
342
343 def end_element_ns(self, name):
/home/kyle/.pyenv/versions/2.7.6/lib/python2.7/site-packages/pyxb/binding/saxer.pyc in startElementNS(self, name, qname, attrs)
368 # Process the element start. This may or may not return a
369 # binding object.
--> 370 binding_object = this_state.startBindingElement(type_class, new_object_factory, element_decl, attrs)
371
372 # If the top-level element has complex content, this sets the
/home/kyle/.pyenv/versions/2.7.6/lib/python2.7/site-packages/pyxb/binding/saxer.pyc in startBindingElement(self, type_class, new_object_factory, element_decl, attrs)
205 try:
206 pyxb.namespace.NamespaceContext.PushContext(self.namespaceContext())
--> 207 self.__constructElement(new_object_factory, attrs)
208 finally:
209 pyxb.namespace.NamespaceContext.PopContext()
/home/kyle/.pyenv/versions/2.7.6/lib/python2.7/site-packages/pyxb/binding/saxer.pyc in __constructElement(self, new_object_factory, attrs, content)
133 # The binding instance may be a simple type that does not support
134 # attributes; the following raises an exception in that case.
--> 135 self.__bindingInstance._setAttribute(attr_en, attrs.getValue(attr_name))
136
137 return self.__bindingInstance
/home/kyle/.pyenv/versions/2.7.6/lib/python2.7/site-packages/pyxb/binding/basis.pyc in _setAttribute(self, attr_en, value_lex)
2236 if self._AttributeWildcard is None:
2237 import ipdb; ipdb.set_trace()
-> 2238 raise pyxb.UnrecognizedAttributeError(type(self), attr_en, self)
2239 self.__wildcardAttributeMap[attr_en] = value_lex
2240 else:
UnrecognizedAttributeError: (<class '_nsgroup_.CT_Document'>, <pyxb.namespace.ExpandedName object at 0x2020bd0>, <_nsgroup_.CT_Document object at 0x2020450>, pyxb.utils.utility.Location(None, 2, 0))
The traceback doesn't actually indicate the attribute name, which itself is unfortunate. attr_en
is passed in the exception, but it's not evaluated unless you convert it to a string. I used a ipdb.set_trace
(apparent in the above traceback) to reveal the attribute name.