Menu

Default namespace in XML without prefix?

Help
Buse
2011-04-06
2013-03-06
  • Buse

    Buse - 2011-04-06

    Greetings,

    I have some XML that I'm trying to parse against a schema and I'm getting odd errors.

    First, the .xsd schema looks like:

    <?xml version="1.0"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
        xmlns="http://xml.example.com/thing"
        targetNamespace="http://xml.example.com/thing">
       .... lots of elements ....
        <xs:element name="CmdServerResponse">
            <xs:complexType>
                    ....  more stuff ....
            </xs:complexType>
        </xs:element>
    </xs:schema>
    

    Now the XML I'm trying to parse looks like this:

       <CmdServerResponse xmlns="http://xml.example.com/thing">
           ...  lots of tags ....
          </CmdServerResponse>
    

    The parse Fails with:

    pyxb.exceptions_.UnrecognizedContentError: UnrecognizedContentError: too few
    

    Now if I change the xml to include the namespace prefix (xmlns:TH), it parses just fine.

       <TH:CmdServerResponse xmlns:TH="http://xml.example.com/thing">
           ...  lots of tags ....
          </TH:CmdServerResponse>
    

    My problem is, my XML is coming from a Legacy source and I can not modify it on that end.  So, Is a default namespace specifier xmlns without a prefix out of spec or is this a bug?  Am I going to have to do some translations and put in that prefix before I let PyXB parse it?

    Thank You

     
  • Buse

    Buse - 2011-04-06

    Sorry, Those semicolons after the <CmdServerResponse> Tags are not actually there.  Typo.

     
  • Peter A. Bigot

    Peter A. Bigot - 2011-04-06

    No, that should all work fine.  The Unrecognized Content Error "too few" is a cryptic indication that the incoming document does not validate: the content model has a minimum occurrence requirement that is not met.  You might try adding

    pyxb.RequireValidWhenParsing(false)
    

    to see what happens when validation is turned off.

     

Log in to post a comment.