OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help



   Problem associating an XML document with an XML schema

[ Lists Home | Date Index | Thread Index ]


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 =
        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";


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"/>

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



News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS