Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

XML validation with XSD

Posted on 2009-05-13
5
Medium Priority
?
691 Views
Last Modified: 2013-11-19
Hello Experts,

I'm getting the following error with my validation:
System.Xml.Schema.XmlSchemaValidationException: The 'request' element is not declared.

Any ideas?

Thanks
Don
XSD:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="request">
    <xs:complexType id="request">
      <xs:sequence>
        <xs:element name="username" type="xs:string" />
        <xs:element name="password" type="xs:string" />
        <xs:element name="hotelid" type="xs:positiveInteger" />
        <xs:element name="startdate" type="xs:string" />
        <xs:element name="enddate" type="xs:string" />
        <xs:element name="roomid" type="xs:positiveInteger" minOccurs="0" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>
 
XML
<?xml version="1.0" ?>
<request>
  <userName>hotel</userName>
  <password>password</password>
  <hotelId>628</hotelId>
  <startDate>23/07/2009</startDate>
  <endDate>26/07/2009</endDate>
  <roomId>0</roomId>
  <mycat></mycat>
</request>

Open in new window

0
Comment
Question by:WorldBlueAustralia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 5

Expert Comment

by:Aanvik
ID: 24380977
<mycat></mycat>

Is missing in XSD
0
 

Author Comment

by:WorldBlueAustralia
ID: 24381054
Thanks Aanvik,

That was a test for me to see if if was validating. I removed it with no result.

Have a look at my post and read the error message.
The 'request' element is not declared.

I think the problem in in the root element.

Cheers
Don
0
 
LVL 27

Expert Comment

by:BigRat
ID: 24383222
In the schema :-

username should be userName
hotelid should be hotelId
startdate should be startDate
enddata should be endData
roomid shoukld be roomId

Or of couse the other way round!
0
 
LVL 27

Accepted Solution

by:
BigRat earned 2000 total points
ID: 24383254
And now to the real problems

1) the XSD should define each element in turn (none other than request are defined)

2) the elements INSIDE an element should be references :-

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="request">
    <xs:complexType id="request">
      <xs:sequence>
        <xs:element ref="userName"/>
        <xs:element ref="password"/>
        <xs:element ref="hotelId" />
        <xs:element ref="startDate"/>
        <xs:element ref="endDate" />
        <xs:element ref="roomId" minOccurs="0" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>
        <xs:element name="userName" type="xs:string" />
        <xs:element name="password" type="xs:string" />
        <xs:element name="hotelId" type="xs:positiveInteger" />
        <xs:element name="startDate" type="xs:string" />
        <xs:element name="endDate" type="xs:string" />
        <xs:element name="roomId" type="xs:positiveInteger"/>
</xs:schema>
 
0
 

Author Closing Comment

by:WorldBlueAustralia
ID: 31581288
Thanks Big Rat, I got the xml to start using the XSD to validate. My next project is to do it progamatically. I'll post that question now.
"Progamatically validate passed in XML with external XSD"

Many thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question