One possibality of getting this error message because u may be using the
old version of Xerces, so download the latest version of Xerces
and keep the new xerces.jar in ur classpath.

i think this will solve ur problem

Regards
Vijay

-----Original Message-----
From: tom john [mailto:[EMAIL PROTECTED]
Sent: Thursday, April 04, 2002 4:06 PM
To: [EMAIL PROTECTED]
Subject: xml validation with schema ERROR


Hi,
I am new validating xml with schema. I get the
following error message when i try to validate xml:

org.xml.sax.SAXNotRecognizedException:
http://apache.org/xml/feature
s/validation/schema-full-checking
Error:  org.xml.sax.SAXParseException: Document root
element "PERSON
", must match DOCTYPE root "null".
Error:  org.xml.sax.SAXParseException: Document is
invalid: no gramm
ar found.
java.lang.NullPointerException

I know the xml document i have is valid. 
the xml i have is:

<?xml version="1.0" encoding="UTF-8"?>
<PERSON NAME="XXX"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:noNamespaceSchemaLocation="mySchema.xsd">
        <COUNTRY>countryName</COUNTRY>
        <COUNTRY>countryName</COUNTRY>
</PERSON>

schema for it is:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
elementFormDefault="qualified">
        <xs:element name="PERSON">
                <xs:complexType>
                        <xs:sequence>
                                <xs:element name="COUNTRY"
type="xs:string"
maxOccurs="unbounded"/>
                        </xs:sequence>
                        <xs:attribute name="NAME" type="xs:string"
use="required"/>
                </xs:complexType>
        </xs:element>
</xs:schema>

The code i am using to validate is:

import org.apache.xerces.parsers.DOMParser;
import org.apache.xerces.parsers.SAXParser;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;
import java.io.IOException;

import java.io.File;

//  A Valdating DOM Application
//  with registered Error Handlers
public class SchemaValidate implements ErrorHandler {

    // Constructor
    public SchemaValidate (String xmlFile) {

        //  Create a Xerces DOM Parser
        DOMParser parser = new DOMParser();
        //SAXParser parser = new SAXParser();
        //MyResolver resolver = new MyResolver();

        //  Turn Validation on
        try {
           
parser.setFeature("http://xml.org/sax/features/validation";,
true);
           
//parser.setProperty("http://apache.org/xml/properties/schema/external-n
oNamespaceSchemaLocation",
"ebxml.xsd");

            //parser.setEntityResolver(resolver);
           
parser.setFeature("http://apache.org/xml/features/validation/schema",fal
se);
           
parser.setFeature("http://apache.org/xml/features/validation/schema-full
-checking",false);
           
parser.setFeature("http://apache.org/xml/features/validation/dtd",false)
;
        }
        catch (SAXNotRecognizedException e) {
            System.err.println (e);
        }
        catch (SAXNotSupportedException e) {
            System.err.println (e);
        }

        //  Register Error Handler
        parser.setErrorHandler (this);

        //  Parse the Document
        try {
            parser.parse(xmlFile);
        }
        catch (SAXException e) {
            System.err.println (e);
        }
        catch (IOException e) {
            System.err.println (e);
        }
        catch (Exception e) {
            System.err.println (e);
        }

    }

    //  Warning Event Handler
    public void warning (SAXParseException e)
        throws SAXException {
        System.err.println ("Warning:  "+e);
    }

    //  Error Event Handler
    public void error (SAXParseException e)
        throws SAXException {
        System.err.println ("Error:  "+e);
    }

    //  Fatal Error Event Handler
    public void fatalError (SAXParseException e)
        throws SAXException {
        System.err.println ("Fatal Error:  "+e);
    }

    // Main Method
    public static void main (String[] args) {
        SchemaValidate validatingDOM = new
SchemaValidate("D:\\tmp\\myxml.xml");
    }
}

thankx

__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to