W3C home > Mailing lists > Public > xmlschema-dev@w3.org > October 2004

Re: Facing problem when validating XML with multiple root node Schema

From: Vineet Chopra <incivinci@gmail.com>
Date: Sat, 16 Oct 2004 20:25:42 +0400
Message-ID: <d83486c70410160925459238fc@mail.gmail.com>
To: xmlschema-dev@w3.org

Hi all,

I am posting a set of sample XMLs which needs to be validated by the schema - 

1- <?xml version="1.0" encoding="WINDOWS-1256" ?><Response><Head
er><FusionInfo><Process ID="0" Name="processName"/><Activity ID="0"
Name="processName"/><TransactionID>61020040044</Transactio
nID></FusionInfo><DepartmentInfo><Sender><Id>140</Id><Description>DNRD</Description></Sender><Receiver><Id>180</Id><Descriptio
n>DMC</Description></Receiver><Transaction><Type>2</Type><ProcessType>SynSingle_PR</ProcessType><Date>2004-10-06
09:16:31</Dat
e><ReferenceNumber>ReferenceNumber
0</ReferenceNumber></Transaction></DepartmentInfo></Header><Body><Process><Id>EMCS-005</Id>
<Description>Acknowledgement</Description><Status>1</Status><Comments>OK</Comments></Process><AcknowledgementInfo><Committed>T
rue</Committed><Duplicate>False</Duplicate></AcknowledgementInfo></Body></Response>

2 - <Request><Header><FusionInfo><Process ID="0" Name="processName"/><
Activity ID="0"
Name="processName"/><TransactionID>61020040044</TransactionID></FusionInfo><DepartmentInfo><Sender><Id>140</Id
><Description>DNRD</Description></Sender><Receiver><Id>180</Id><Description>DMC</Description></Receiver><Transaction><Type>1</
Type><ProcessType>SynSingle_PR</ProcessType><Date>2004-10-06
09:16:32</Date><ReferenceNumber>ReferenceNumber 0</ReferenceNumbe
r></Transaction></DepartmentInfo></Header><Body><Process><Id>EMCS-002</Id><Description>Medical
Certificate Result</Description
><Status>1</Status><Comments>OK</Comments></Process><ApplicantInfo><Applicant><PersonType>2</PersonType><PersonNumber>20120037
072838</PersonNumber><ApplicantNameEN>FREDRIEK
XAVIER</ApplicantNameEN><Status>1</Status><Comments>Updated
Successfully</Comme
nts></Applicant><Applicant><PersonType>2</PersonType><PersonNumber>20120042150681</PersonNumber><ApplicantNameEN>SAM
OSWALD</Applica
ntNameEN><Status>1</Status><Comments>Updated
Successfully</Comments></Applicant></ApplicantInfo></Body></Request>

Thanks for the interest.

I want to point a few more details. 

- The Operating System is Sun OS 5.0. No problems on Windows.

- The XML is being streamed over a HTTP connections, received by a
Servlet and routed to certain helper classes for further processed.

- A standalone pseudo code written with the same logical steps happens
to validate the XML without any errors in both OS. In this I am
parsing a XML string as compared to an input stream in the latter
case.

Thanks,
Vineet.





On Thu, 14 Oct 2004 10:39:31 +0400, Vineet Chopra <incivinci@gmail.com> wrote:
> Hi all,
> 
> I will make things more clear -
> 
> Can anybody point out the problem -
> 
> I have a multiple root node schema. And I am validation my XML against
> this schema using JDOM with XercesJ parser. Code sections as follows -
> 
> ===========================================================
> if(new Boolean(CommonsUtil.readProps(Globals.SERVICE_ID,
> "xmlSchemaValidation")).booleanValue()){
> log.debug("Started validating XML against defined schema");
> builder.setValidation(true);
> XMLParseErrorHandler errorHandler = new XMLParseErrorHandler(xml);
> builder.setErrorHandler(errorHandler);
> builder.setFeature("http://apache.org/xml/features/validation/schema", true);
> builder.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",
> CommonsUtil.readProps(Globals.SERVICE_ID, "xmlSchemaLocation"));
> 
> }else{
> log.debug("XML Schema Validation switched off");
> }
> Document doc = builder.build(src);
> 
> ===========================================================
> The parser validates one XML with root node "Response" but gives the
> following error while validating XML with root node "Request" -
> 
> Error: cvc-elt.1: Cannot find the declaration of element 'Request'. at
> line 1, co
> lumn 10 in entity null
> 
> I know that the error description suggests that there is no definition
> for the tag "Request" in the schema. But I have cross checked the
> schema and the XML with XMLSpy, no problem in that.
> 
> Here is the schema, though a long one -
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> elementFormDefault="qualified">
>        <xs:element name="Activity">
>                <xs:complexType>
>                        <xs:attribute name="ID" type="xs:string" use="required"/>
>                        <xs:attribute name="Name" type="xs:string" use="required"/>
>                </xs:complexType>
>        </xs:element>
>        <xs:element name="Applicant">
>                <xs:complexType>
>                        <xs:all>
>                                <xs:element ref="ApplicantNameAR" minOccurs="0"/>
>                                <xs:element ref="ApplicantNameEN" minOccurs="0"/>
>                                <xs:element ref="BirthPlaceAR" minOccurs="0"/>
>                                <xs:element ref="BirthPlaceEN" minOccurs="0"/>
>                                <xs:element ref="Comments" minOccurs="0"/>
>                                <xs:element ref="DOB" minOccurs="0"/>
>                                <xs:element ref="EmiratesId" minOccurs="0"/>
>                                <xs:element ref="EmiratesID" minOccurs="0"/>
>                                <xs:element ref="EmiratesDescAR" minOccurs="0"/>
>                                <xs:element ref="EmiratesDescEN" minOccurs="0"/>
>                                <xs:element ref="JobId" minOccurs="0"/>
>                                <xs:element ref="JobDescAR" minOccurs="0"/>
>                                <xs:element ref="JobDescEN" minOccurs="0"/>
>                                <xs:element ref="McValidityDate" minOccurs="0"/>
>                                <xs:element ref="McStatus" minOccurs="0"/>
>                                <xs:element ref="NationalityId" minOccurs="0"/>
>                                <xs:element ref="NationalityDescAR" minOccurs="0"/>
>                                <xs:element ref="NationalityDescEN" minOccurs="0"/>
>                                <xs:element ref="POBox" minOccurs="0"/>
>                                <xs:element ref="PersonType" minOccurs="0"/>
>                                <xs:element ref="PersonNumber" minOccurs="0"/>
>                                <xs:element ref="Passport" minOccurs="0"/>
>                                <xs:element ref="PassportNb" minOccurs="0"/>
>                                <xs:element ref="Sex" minOccurs="0"/>
>                                <xs:element ref="Sponsor" minOccurs="0"/>
>                                <xs:element ref="Status" minOccurs="0"/>
>                        </xs:all>
>                </xs:complexType>
>        </xs:element>
>        <xs:element name="AcknowledgementInfo">
>                <xs:complexType>
>                        <xs:all>
>                                <xs:element ref="Committed"/>
>                                <xs:element ref="Duplicate"/>
>                        </xs:all>
>                </xs:complexType>
>        </xs:element>
>        <xs:element name="ApplicantInfo">
>                <xs:complexType>
>                        <xs:sequence>
>                                <xs:element ref="Applicant" maxOccurs="unbounded"/>
>                        </xs:sequence>
>                </xs:complexType>
>        </xs:element>
>        <xs:element name="ApplicantNameAR" type="xs:string"/>
>        <xs:element name="ApplicantNameEN" type="xs:string"/>
>        <xs:element name="AreaId" type="xs:string"/>
>        <xs:element name="AreaDescAR" type="xs:string"/>
>        <xs:element name="AreaDescEN" type="xs:string"/>
>        <xs:element name="BirthPlaceAR" type="xs:string"/>
>        <xs:element name="BirthPlaceEN" type="xs:string"/>
>        <xs:element name="Building" type="xs:string"/>
>        <xs:element name="Body">
>                <xs:complexType>
>                        <xs:all>
>                                <xs:element ref="Process"/>
>                                <xs:element ref="ApplicantInfo" minOccurs="0"/>
>                                <xs:element ref="AcknowledgementInfo" minOccurs="0"/>
>                        </xs:all>
>                </xs:complexType>
>        </xs:element>
>        <xs:element name="CityId" type="xs:string"/>
>        <xs:element name="CityDescAR" type="xs:string"/>
>        <xs:element name="CityDescEN" type="xs:string"/>
>        <xs:element name="Committed" type="xs:string"/>
>        <xs:element name="Contact1" type="xs:string"/>
>        <xs:element name="Contact2" type="xs:string"/>
>        <xs:element name="Comments" type="xs:string"/>
>        <xs:element name="DOB" type="xs:string"/>
>        <xs:element name="Duplicate" type="xs:string"/>
>        <xs:element name="Date" type="xs:string"/>
>        <xs:element name="DepartmentInfo">
>                <xs:complexType>
>                        <xs:all>
>                                <xs:element ref="Sender"/>
>                                <xs:element ref="Receiver"/>
>                                <xs:element ref="Transaction"/>
>                        </xs:all>
>                </xs:complexType>
>        </xs:element>
>        <xs:element name="Description" type="xs:string"/>
>        <xs:element name="EmiratesDescAR" type="xs:string"/>
>        <xs:element name="EmiratesDescEN" type="xs:string"/>
>        <xs:element name="ExpiryDate" type="xs:string"/>
>        <xs:element name="EmiratesId" type="xs:string"/>
>        <xs:element name="EmiratesID" type="xs:string"/>
>        <xs:element name="FlatNumber" type="xs:string"/>
>        <xs:element name="FusionInfo">
>                <xs:complexType>
>                        <xs:all>
>                                <xs:element ref="Activity"/>
>                                <xs:element ref="Process"/>
>                                <xs:element ref="TransactionID"/>
>                        </xs:all>
>                </xs:complexType>
>        </xs:element>
>        <xs:element name="Header">
>                <xs:complexType>
>                        <xs:all>
>                                <xs:element ref="DepartmentInfo"/>
>                                <xs:element ref="FusionInfo"/>
>                        </xs:all>
>                </xs:complexType>
>        </xs:element>
>        <xs:element name="Id">
>                <xs:simpleType>
>                        <xs:restriction base="xs:string">
>                                <xs:enumeration value="140"/>
>                                <xs:enumeration value="180"/>
>                                <xs:enumeration value="EMCS-001"/>
>                                <xs:enumeration value="EMCS-002"/>
>                                <xs:enumeration value="EMCS-003"/>
>                                <xs:enumeration value="EMCS-004"/>
>                                <xs:enumeration value="EMCS-005"/>
>                        </xs:restriction>
>                </xs:simpleType>
>        </xs:element>
>        <xs:element name="IssueDate" type="xs:string"/>
>        <xs:element name="JobDescAR" type="xs:string"/>
>        <xs:element name="JobDescEN" type="xs:string"/>
>        <xs:element name="JobId" type="xs:string"/>
>        <xs:element name="McValidityDate" type="xs:string"/>
>        <xs:element name="McStatus" type="xs:string"/>
>        <xs:element name="NameAR" type="xs:string"/>
>        <xs:element name="NameEN" type="xs:string"/>
>        <xs:element name="NationalityId" type="xs:string"/>
>        <xs:element name="NationalityDescAR" type="xs:string"/>
>        <xs:element name="NationalityDescEN" type="xs:string"/>
>        <xs:element name="Number" type="xs:string"/>
>        <xs:element name="POBox" type="xs:string"/>
>        <xs:element name="Passport">
>                <xs:complexType>
>                        <xs:all>
>                                <xs:element ref="ExpiryDate"/>
>                                <xs:element ref="IssueDate"/>
>                                <xs:element ref="Number"/>
>                        </xs:all>
>                </xs:complexType>
>        </xs:element>
>        <xs:element name="PassportNb" type="xs:string"/>
>        <xs:element name="PersonNumber" type="xs:string"/>
>        <xs:element name="PersonType" type="xs:string"/>
>        <xs:element name="Process">
>                <xs:complexType>
>                        <xs:all>
>                                <xs:element ref="Comments" minOccurs="0"/>
>                                <xs:element ref="Id" minOccurs="0"/>
>                                <xs:element ref="Description" minOccurs="0"/>
>                                <xs:element ref="Status" minOccurs="0"/>
>                        </xs:all>
>                        <xs:attribute name="ID" type="xs:string" use="optional"/>
>                        <xs:attribute name="Name" type="xs:string" use="optional"/>
>                </xs:complexType>
>        </xs:element>
>        <xs:element name="ProcessType" type="xs:string"/>
>        <xs:element name="Receiver">
>                <xs:complexType>
>                        <xs:all>
>                                <xs:element ref="Id"/>
>                                <xs:element ref="Description"/>
>                        </xs:all>
>                </xs:complexType>
>        </xs:element>
>        <xs:element name="ReferenceNumber" type="xs:string"/>
>        <xs:element name="Response">
>                <xs:complexType>
>                        <xs:all>
>                                <xs:element ref="Header"/>
>                                <xs:element ref="Body"/>
>                        </xs:all>
>                </xs:complexType>
>        </xs:element>
>        <xs:element name="Request">
>                <xs:complexType>
>                        <xs:all>
>                                <xs:element ref="Header"/>
>                                <xs:element ref="Body"/>
>                        </xs:all>
>                </xs:complexType>
>        </xs:element>
>        <xs:element name="Status" type="xs:string"/>
>        <xs:element name="Sex" type="xs:string"/>
>        <xs:element name="Sponsor">
>                <xs:complexType>
>                        <xs:all>
>                                <xs:element ref="AreaId"/>
>                                <xs:element ref="AreaDescAR"/>
>                                <xs:element ref="AreaDescEN"/>
>                                <xs:element ref="Building"/>
>                                <xs:element ref="CityId"/>
>                                <xs:element ref="CityDescAR"/>
>                                <xs:element ref="CityDescEN"/>
>                                <xs:element ref="Contact1"/>
>                                <xs:element ref="Contact2"/>
>                                <xs:element ref="EmiratesId"/>
>                                <xs:element ref="EmiratesDescAR"/>
>                                <xs:element ref="EmiratesDescEN"/>
>                                <xs:element ref="FlatNumber"/>
>                                <xs:element ref="NameAR"/>
>                                <xs:element ref="NameEN"/>
>                                <xs:element ref="SponsorType"/>
>                                <xs:element ref="SponsorNumber"/>
>                                <xs:element ref="Street"/>
>                        </xs:all>
>                </xs:complexType>
>        </xs:element>
>        <xs:element name="SponsorType" type="xs:string"/>
>        <xs:element name="SponsorNumber" type="xs:string"/>
>        <xs:element name="Street" type="xs:string"/>
>        <xs:element name="Sender">
>                <xs:complexType>
>                        <xs:all>
>                                <xs:element ref="Id"/>
>                                <xs:element ref="Description"/>
>                        </xs:all>
>                </xs:complexType>
>        </xs:element>
>        <xs:element name="Transaction">
>                <xs:complexType>
>                        <xs:all>
>                                <xs:element ref="Type"/>
>                                <xs:element ref="ProcessType"/>
>                                <xs:element ref="Date"/>
>                                <xs:element ref="ReferenceNumber"/>
>                        </xs:all>
>                </xs:complexType>
>        </xs:element>
>        <xs:element name="TransactionID" type="xs:string"/>
>        <xs:element name="Type" type="xs:string"/>
> </xs:schema>
> 
> Thanks once again.
> 
> 
> 
> 
> On Tue, 12 Oct 2004 16:50:41 +0400, Vineet Chopra <incivinci@gmail.com> wrote:
> > Hello,
> >
> > I am facing a problem while validating an XML document against a
> > schema, using JDOM with XercesJ parser.
> >
> > Description -
> >
> > My code is consuming XML messages sent over HTTP Connection. I want to
> > validate the XML messages before parsing the same. For this I have
> > created a single Schema which defines all incoming XML messages. The
> > resultant schema has multiple root nodes.
> >
> > The code validates one root node for an incoming XML mesaage but fails
> > to validate root nodes of another XML messages.
> >
> > The error which I get is
> >
> > Error: cvc-elt.1: Cannot find the declaration of element 'Request'. at
> > line 1, column 10 in entity null
> >
> > The schema does contain a definition for the tag "Request". I have
> > cross checked it umpteen times.
> >
> > I shall be thankful if you throw some light on this.
> >
> > Vineet Chopra
> >
>
Received on Saturday, 16 October 2004 16:25:43 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 5 February 2014 07:15:11 UTC