[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Problem associating an XML document with an XML schema

  • To: <xml-dev@l...>
  • Subject: Problem associating an XML document with an XML schema
  • From: "Peter Loh Yoon Chao" <yoonchao@s...>
  • Date: Sat, 7 Feb 2004 12:44:58 +0800
  • Importance: Normal

test xml schema
Hi,

As I am new to the world of XML and Java, I was exploring how I could
associate an XML document (whose name is passed in via the command line)
with an XML schema for validation purposes using the related Java DOM API.
The relevant Java code is as follows:

        DocumentBuilderFactory factory =
                DocumentBuilderFactory.newInstance();
        factory.setValidating(true);
        factory.setNamespaceAware(true);
        try {
            DocumentBuilder builder = factory.newDocumentBuilder();
            //builder.setErrorHandler(new MyErrorHandler());
            document = builder.parse(new File(args[0]));
        } catch (SAXException sxe) {
	...

I am using the following simple XML document (test.xml):

<?xml version="1.0" encoding="ISO-8859-1"?>

 <shiporder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:noNamespaceSchemaLocation="file:///C:/j2sdk1.4.2/practice/test.xsd">2003
-02-06</shiporder>

The corresponding XML schema (test.xsd) is as follows:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
 <xs:element name="shiporder" type="xs:date"/>
</xs:schema>

When I ran the Java program, I got the following errors:

Error: URI=file:C:/j2sdk1.4.2/practice/test.xml Line=3: Element type
"shiporder"
 is not declared.
Error: URI=file:C:/j2sdk1.4.2/practice/test.xml Line=4: Attribute
"xmlns:xsi" is
 not declared for element "shiporder".
Error: URI=file:C:/j2sdk1.4.2/practice/test.xml Line=4: Attribute
"xsi:noNamespa
ceSchemaLocation" is not declared for element "shiporder".

It seems that somehow the schema was not used for validation.  Since I was
using the "xsi:noNamespaceSchemaLocation" attribute in my XML document, I
had actually started out by omitting the path to test.xsd (as this was in
the same location as the XML document).  The same errors were also thrown in
this scenario.

Would appreciate any input on where I might have gone wrong.  Thanks.

Peter


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.