*
The moose likes Product and Other Certifications and the fly likes Validating an Instance Document Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Product and Other Certifications
Bookmark "Validating an Instance Document" Watch "Validating an Instance Document" New topic
Author

Validating an Instance Document

Hongqing Lu
Greenhorn

Joined: Jan 14, 2004
Posts: 13
I want to validate an instance document user.xml based on user.xsd.
user.xsd:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="user">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="age" type="xs:integer"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
xml file is user.xml:
<?xml version="1.0"?>
<user xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="user.xsd">
<name>Tony</name>
<age>24</age>
</user>
when I begin to validate the user.xml based user.xsd
the parser give the following error:
unable to determine location of schema components set
Both user.xsd and user.xml in the same directory in my pc.
How to fix it?
Any help would be appreciated.
Andy Smith
Ranch Hand

Joined: Sep 28, 2003
Posts: 239
Try using
<xsi:noNamespaceSchemaLocation="user.xsd">
as u hav not mentioned any targetNamespace in ur Schema so use noNamespaceSchemaLocation instead of schemaLocation.
This might work. plz check..


Share Knowledge to gain it.
SCJP 2, SCWCD 2, SCDJWS, IBM 141 (In Progress), IBM 486 (Next)
Marcelo Sousa Ancelmo
Ranch Hand

Joined: Jan 17, 2002
Posts: 497

Are you using Xerces-J to validate the document?
To validate a XML Document using Xerces do the following (I believe you are using JAXP):

The System property can be passed as a command line argument using -D option or can be put in a property file.
In this example I used a SAX based approach, but you can use DOM as well
Regards,


Marcelo Sousa Ancelmo - Brazil
 
wood burning stoves
 
subject: Validating an Instance Document
 
Similar Threads
xml validation error:Caused by: nu.xom.ValidityException: Document is invalid: no grammar found
Jaxb marshalling exception
[schema] Allow an element to have any content
Unqualified elment - but still have prefix at the root
root element to wrap all the complexType elements