[xsd-users] looking for help designing my XSD to work with my XML's namespace

Mike Kowdley mikekowdley at yahoo.com
Sun Aug 14 17:51:01 EDT 2011


Hello all,

I am receiving an XML file and am trying to design an XSD that will allow me to parse it using the xsd cxx-tree tool.  I am using CodeSynthesis XSD 3.3.0.  The document is failing to parse and I am not sure how to correct my XSD document.


My XML document looks something like this:
<?xml version="1.0" encoding="UTF-8"?>
<ReferenceInformation  Major="3" Minor="0" Revision="1" xmlns="urn:dataprovidercontent:referenceinformation03">
<Identifier>1234</Identifier>
<CompanyInformation>
  <Element>data</Element>
  <Element>data</Element>
</CompanyInformation>
</ReferenceInformation>

And my XSD looks something like this:
<xsd:schema  xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" jxb:version="2.0">
  <xsd:element name="ReferenceInformation" type="ReferenceInformationType" />
  <xsd:complexType name="ReferenceInformationType">
    <xsd:sequence>
      <xsd:element name="Identifier" type="xsd:string" minOccurs="1" maxOccurs="1" />
      <xsd:element name="CompanyInformation" type="CompanyInformationType" minOccurs="1" maxOccurs="1" />
    </xsd:sequence>
    <xsd:attribute name="Major" type="xsd:string" />
    <xsd:attribute name="Minor" type="xsd:string" />
    <xsd:attribute name="Revision" type="xsd:string" />
  </xsd:complexType>
  <xsd:complexType name="CompanyInformationType">
    <xsd:sequence>
      <xsd:element name="Element" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
    </xsd:sequence>
  </xsd:complexType>

</xsd:schema>


I have changed some of the names to protect the innocent.

If I try to parse this document I get an unexpected element exception.
expected_namespace:
expected_name: ReferenceInformation

encountered_namespace: urn:dataprovidercontent:referenceinformation03
encountered_name: ReferenceInformation

I have also found that if I edit the XML document and remove the xmlns attribute from the <ReferenceInformation> start tag, then the document parses without any error.

It seems that the xmlns attribute to the <ReferenceInformation> tag needs to be noted in the XSD document. 


I'm equally happy solving this the "right" way (getting my XSD to be correct for parsing this document) or the "wrong" way (convining the parser to ignore the namespace, or something similar) but I am pretty new to this so I'm not sure how to proceed.

Hopefully my question is succinct enough that it's an easy answer!  Thanks in advance for reading this question.

Regards,
Mike K.


More information about the xsd-users mailing list