XML validation with XSD

Posted on 2009-05-13
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?

<?xml version="1.0"?>
<xs:schema xmlns:xs="">
  <xs:element name="request">
    <xs:complexType id="request">
        <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" />
<?xml version="1.0" ?>

Open in new window

Question by:WorldBlueAustralia
  • 2
  • 2

Expert Comment

ID: 24380977

Is missing in XSD

Author Comment

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.

LVL 27

Expert Comment

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!
LVL 27

Accepted Solution

BigRat earned 500 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="">
  <xs:element name="request">
    <xs:complexType id="request">
        <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: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"/>

Author Closing Comment

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

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System ( introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

861 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