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 an Instance Document

 
Hongqing Lu
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 239
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
Marcelo Sousa Ancelmo
Ranch Hand
Posts: 498
Eclipse IDE Fedora Firefox Browser
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic