File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Java Interview Guide this week in the Jobs Discussion 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

Validating a xml doc against schema

Himal Chuli
Ranch Hand

Joined: Aug 06, 2002
Posts: 118
i'm confused about validation of xml doc against its schema. suppose i've the followings:
XML file ("note.xml"):
<?xml version="1.0"?>
xmlns="" xmlns:xsi=""
<body>Don't forget me this weekend!</body>
And the schema ("note.xsd"):
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs=""
<xs:element name="note">
<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"/>
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.

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: 1183
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.

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.
Balaji Loganathan
author and deputy

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.

Spritle Software Blogs
I agree. Here's the link:
subject: Validating a xml doc against schema
It's not a secret anymore!