I just finished struggling with this same problem. I had to change
several things to make it work.
You did not say which version of Xerces-J you are using. I urge you to
download 1.4.0 to get the latest schema handling. I did, and my code
examples are based on using version 1.4.0.
My java file contains this code:
DOMParser parser = new DOMParser();
MyErrorHandler errHandler = new MyErrorHandler();
try {
parser.setFeature("http://apache.org/xml/features/dom/defer-node-expansion",true);
parser.setFeature("http://xml.org/sax/features/validation", true );
parser.setFeature("http://xml.org/sax/features/namespaces", true );
parser.setFeature("http://apache.org/xml/features/validation/schema",true);
parser.setErrorHandler(errHandler);
parser.parse(xmlFile);
where "MyErrorHandler" is a Java class that I wrote which implements the
ErrorHandler interface.
I tested this using the personal-schema.xml and personal.xsd files that
come with the Xerces package.
My schema file contains this:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns='http://www.w3.org/2001/XMLSchema'>
XMLSpy creates schema which contain the string "2000/10", not "2001".
You must edit the .xsd file to change this.
My .xml file contains this:
<?xml version="1.0" encoding="UTF-8"?>
<personnel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation='personal.xsd'>
The parser apparently assumes that the schema is in the same directory
as the xml file. If it is not, I had to fully qualify it like this:
xsi:noNamespaceSchemaLocation='file:///c:/xerces-1_4_0/data/personal.xsd'>
I had to do all these things (setFeatures, change "2000/10" to "2001",
and fully qualify the schema location) to get the validation to work.
Good luck.
Mary Ryan
Space Telescope Science Institute
[EMAIL PROTECTED]
-------------------------------------------------------------------------------------------
> "Hunter, Francine" wrote:
>
> Hi, I am trying to validate a XML document using Xerces against a 2000
> schema
>
> I am using XMLSPY 3.5 to create the documents which uses the 2000
> standards. I don't really know if this makes a difference. But I can't
> get the validation to seem to recognize the Schema file at all.
>
> Here is what the header of the files look like. Is this correct
>
> XML file:
> <?xml version="1.0" encoding="UTF-8"?>
> <datamart xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
> xsi:noNamespaceSchemaLocation="D:\Development\LOM 6.0 (Rio
> Grande)\Resources\datamart.xsd">
>
> <dateDimension name="DATE_DIM" yearRange="10"
> startDate="02/14/2000">
> ...
>
> Schema file:
> <!-- edited with XML Spy v3.5 NT (http://www.xmlspy.com) by Greg
> Heidel (eLoyalty) -->
> <xsd:schema xmlns:xsd="http://www.w3.org/2000/10/XMLSchema"
> elementFormDefault="qualified">
> <xsd:element name="datamart">
> <xsd:complexType>
> <xsd:sequence>
> <xsd:element name="table"
> maxOccurs="unbounded">
>
> ...
>
> Are there any obvious mistakes here.
>
> The error message I get back is:
>
> message: Element type "datamart" must be declared.
>
> Thanks. Any help would be appreciated.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]