On Wed, Oct 19, 2011 at 12:03 PM, Marcin Tustin <marcin.tus...@gmail.com>wrote:
> In what sense is the document lying about its namespace? For it to be lying
> would require something substantive of the document that the namespace
> points to, no?
The presence of the following attribute:
xmlns="http://www.govtalk.gov.uk/schemas/govtalk/govtalkheader"
says that any unprefixed element tag within the element should be assumed to
be part of the namespace with that URI. See
http://www.w3.org/TR/REC-xml-names/#defaulting.
The document then goes on to use unprefixed tags like GovTalkMessage. PyXB
therefore needs to know the details of the schema for the namespace
http://www.govtalk.gov.uk/schemas/govtalk/govtalkheader so it can determine
whether the content that the document provides for GovTalkMessage is
consistent with the structure associated with that element in the
namespace's content model.
I suspect that the example document is simply wrong, and hope that the live
service provides valid documents.
If you change the value of the xmlns attribute at the top of the document as
I suggested, and if the remainder of the example is a valid document
corresponding to the http://www.govtalk.gov.uk/CM/envelope namespace, then
PyXB will parse it.
Please review http://www.w3.org/TR/REC-xml-names. The problem is with the
example document, not with PyXB.
Peter
> On Wed, Oct 19, 2011 at 18:01, Peter Bigot <big...@acm.org> wrote:
>
>> On Wed, Oct 19, 2011 at 11:53 AM, Marcin Tustin
>> <marcin.tus...@gmail.com>wrote:
>>
>>> OK, how should I provide the schema to pyxb so that it can decode such
>>> documents? The XSD which I need my documents to conform to is the one from
>>> which I'm generating the code.
>>
>>
>> As far as I can tell, the schema isn't the problem. (You will have to
>> also locate the schema for and generate bindings for
>> http://www.govtalk.gov.uk/CM/core, since the envelope's schema references
>> types defined in that namespace.)
>>
>> The problem is the example document is lying about what namespace its
>> content conforms to. Change:
>>
>> <GovTalkMessage xmlns="
>> http://www.govtalk.gov.uk/schemas/govtalk/govtalkheader"
>>
>> at the top of the document you're parsing to:
>>
>> <GovTalkMessage xmlns="http://www.govtalk.gov.uk/CM/envelope"
>>
>> Peter
>>
>> On Wed, Oct 19, 2011 at 17:46, Peter Bigot <big...@acm.org> wrote:
>>>
>>>> On Wed, Oct 19, 2011 at 11:22 AM, Marcin Tustin <
>>>> marcin.tus...@gmail.com> wrote:
>>>>
>>>>> Hi Peter,
>>>>>
>>>>> Thanks for this. Unless I'm mistaken, namespace URIs are not required
>>>>> to map to any resource at all, let alone an XSD. However, the xsd from
>>>>> which
>>>>> I'm generating the code is at
>>>>> http://xmlgw.companieshouse.gov.uk/v2-1/schema/Egov_ch-v2-0.xsd.
>>>>>
>>>>
>>>> That schema is for namespace http://www.govtalk.gov.uk/CM/envelope.
>>>>
>>>> What is PyXB expecting in its input that could be leading to this? Does
>>>>> it rely on namespaces naming XSD files?
>>>>>
>>>>
>>>> No, PyXB treats namespaces as URIs, not URLs, and has no expectation
>>>> that they can be dereferenced. (It may, when generating bindings, make
>>>> some
>>>> attempt to locate the schema from an xsi:schemaLocation attribute, but that
>>>> shouldn't happen when parsing.)
>>>>
>>>> The example documents (from the link you provided) do not reference the
>>>> namespace http://www.govtalk.gov.uk/CM/
>>>> envelope. They both specify that the default namespace is
>>>> http://www.govtalk.gov.uk/schemas/govtalk/govtalkheader. Unless you
>>>> have a schema for that namespace, PyXB won't be able to decode the content
>>>> of the document.
>>>>
>>>> If the document doesn't specify a default namespace I believe it would
>>>> fall back to the one you used as the CreateFromDocument call, but when the
>>>> document does specify a namespace it's expected to be correct.
>>>>
>>>> Try editing the document and correcting the xmlns= attribute at the root
>>>> so it has the same namespace as the module you're using to parse it.
>>>>
>>>> Peter
>>>>
>>>>
>>>>>
>>>>> On Wed, Oct 19, 2011 at 16:49, Peter Bigot <big...@acm.org> wrote:
>>>>>
>>>>>> On Wed, Oct 19, 2011 at 10:32 AM, Marcin Tustin <
>>>>>> marcin.tus...@gmail.com> wrote:
>>>>>>
>>>>>>> Hi all,
>>>>>>>
>>>>>>> I'm making my first contact with pyxb, and so far it seems to only
>>>>>>> exist to generate odd errors.
>>>>>>>
>>>>>>> I've tried to have it parse a document with:
>>>>>>>
>>>>>>> > import govtalkenvelope as g
>>>>>>> > g.CreateFromDocument("""[xml taken from
>>>>>>> http://xmlgw.companieshouse.gov.uk/example_http.html]""")
>>>>>>> Traceback (most recent call last):
>>>>>>> File "<stdin>", line 35, in <module>
>>>>>>> File "govtalkenvelope.py", line 32, in CreateFromDocument
>>>>>>> saxer.parse(StringIO.StringIO(xml_text))
>>>>>>> File "C:\Python27\Lib\xml\sax\expatreader.py", line 107, in parse
>>>>>>> xmlreader.IncrementalParser.parse(self, source)
>>>>>>> File "C:\Python27\Lib\xml\sax\xmlreader.py", line 123, in parse
>>>>>>> self.feed(buffer)
>>>>>>> File "C:\Python27\Lib\xml\sax\expatreader.py", line 207, in feed
>>>>>>> self._parser.Parse(data, isFinal)
>>>>>>> File "C:\Python27\Lib\xml\sax\expatreader.py", line 338, in
>>>>>>> start_element_ns
>>>>>>> AttributesNSImpl(newattrs, qnames))
>>>>>>> File
>>>>>>> "C:\Users\Marcin\Documents\oneclickcos\lib\site-packages\pyxb\binding\sax
>>>>>>> er.py", line 310, in startElementNS
>>>>>>> element_binding = name_en.elementBinding()
>>>>>>> File
>>>>>>> "C:\Users\Marcin\Documents\oneclickcos\lib\site-packages\pyxb\namespace\_
>>>>>>> _init__.py", line 96, in __getattr__
>>>>>>> category_value =
>>>>>>> self.namespace().categoryMap(name).get(self.localName())
>>>>>>> File
>>>>>>> "C:\Users\Marcin\Documents\oneclickcos\lib\site-packages\pyxb\namespace\_
>>>>>>> _init__.py", line 293, in categoryMap
>>>>>>> raise pyxb.NamespaceError(self, '%s has no category %s' % (self,
>>>>>>> category))
>>>>>>> pyxb.exceptions_.NamespaceError:
>>>>>>> http://www.govtalk.gov.uk/schemas/govtalk/govta
>>>>>>> lkheader has no category elementBinding
>>>>>>>
>>>>>>
>>>>>> It's probably saying it doesn't know how to deal with the
>>>>>> http://www.govtalk.gov.uk/schemas/govtalk/govtalkheader namespace.
>>>>>> Certainly it isn't clear to me where to find a schema for that namespace;
>>>>>> the xsiLocation URI in the sample resolves to a web page, not a schema.
>>>>>>
>>>>>> Did you generate bindings for that namespace? How?
>>>>>>
>>>>>>
>>>>>>>
>>>>>>> Needless to say, it's less than clear what this is supposed to mean.
>>>>>>> Any suggestions as to what might be causing this, or indeed how in
>>>>>>> general
>>>>>>> to deal with pyxb's exception messages?
>>>>>>>
>>>>>>
>>>>>> Experience is the only guide. Sorry, PyXB development is unfunded, so
>>>>>> making it user friendly hasn't gotten much attention.
>>>>>>
>>>>>> Peter
>>>>>>
>>>>>>
>>>>>>>
>>>>>>> Marcin
>>>>>>>
>>>>>>> --
>>>>>>> Marcin Tustin
>>>>>>> Tel: 07773 787 105
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> ------------------------------------------------------------------------------
>>>>>>> All the data continuously generated in your IT infrastructure
>>>>>>> contains a
>>>>>>> definitive record of customers, application performance, security
>>>>>>> threats, fraudulent activity and more. Splunk takes this data and
>>>>>>> makes
>>>>>>> sense of it. Business sense. IT sense. Common sense.
>>>>>>> http://p.sf.net/sfu/splunk-d2d-oct
>>>>>>> _______________________________________________
>>>>>>> pyxb-users mailing list
>>>>>>> pyxb-users@lists.sourceforge.net
>>>>>>> https://lists.sourceforge.net/lists/listinfo/pyxb-users
>>>>>>>
>>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Marcin Tustin
>>>>> Tel: 07773 787 105
>>>>>
>>>>>
>>>>
>>>
>>>
>>> --
>>> Marcin Tustin
>>> Tel: 07773 787 105
>>>
>>>
>>
>
>
> --
> Marcin Tustin
> Tel: 07773 787 105
>
>
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2d-oct
_______________________________________________
pyxb-users mailing list
pyxb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyxb-users