This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Validating a xml doc against schema

 
Himal Chuli
Ranch Hand
Posts: 118
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i'm confused about validation of xml doc against its schema. suppose i've the followings:
XML file ("note.xml"):
----------------------
<?xml version="1.0"?>
<note
xmlns="http://www.w3schools.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3schools.com/schema/note.xsd">
<to>Angel</to>
<from>Helpless</from>
<phone>238768</phone>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
And the schema ("note.xsd"):
-----------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"
xmlns="http://www.w3schools.com"
elementFormDefault="qualified">
<xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
if you look at the "note.xml" file where i've put an element "phone" which is not defined in schema "note.xsd". so when i validate from IE5 by right clicking on it and selecting Validate XML, no erorr is reported. i don't understand why. or is it because my validation process is wrong? my understanding is that a xml doc must not contain an element that's not defined in schema. please clarify me it. thanks.
himal
 
Jayadev Pulaparty
Ranch Hand
Posts: 662
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think for the xsi:schemaLocation you need to give the targetnamespace followed by the schema file name. I guess you missed giving the target namespace here. Try doing it that way.
 
Dan Drillich
Ranch Hand
Posts: 1183
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Himal,
IE5 doesn't validate your XML file. I don't think it even looks at the schema file at all.
In case of a DTD file, IE5 needs to retrieve entity values and default/constant values of attributes from the file. Therefore, IE5 checks the DTD syntax and reports DTD syntax errors.
Cheers,
Dan
 
Himal Chuli
Ranch Hand
Posts: 118
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi dan,
how could i validate a xml doc against its schema then? can you please let me know? would appreciate if anyone could tell me.
thanks.
himal
 
Balaji Loganathan
author and deputy
Bartender
Posts: 3150
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Download Topologi Schematron validator,or XMLSPY or use XSV online at W3C site,or download Sun MSV.....go thorough thier read me files,u will cometo know how to do it.
Regards
balaji
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic