aspose file tools*
The moose likes Product and Other Certifications and the fly likes Validating a xml doc against schema Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Product and Other Certifications
Bookmark "Validating a xml doc against schema" Watch "Validating a xml doc against schema" New topic
Author

Validating a xml doc against schema

Himal Chuli
Ranch Hand

Joined: Aug 06, 2002
Posts: 118
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


Himal
Jayadev Pulaparty
Ranch Hand

Joined: Mar 25, 2002
Posts: 662
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

Joined: Jul 09, 2001
Posts: 1180
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


William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
Himal Chuli
Ranch Hand

Joined: Aug 06, 2002
Posts: 118
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

Joined: Jul 13, 2001
Posts: 3150
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


Spritle Software Blogs
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Validating a xml doc against schema