xerces-j-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Amthauer, Heiner" <Heiner.Amtha...@t-systems.com>
Subject AW: problem using XML schema w/ Xerces 2
Date Tue, 05 Nov 2002 07:43:23 GMT
Hi!

This has been discussed quite a few times, lately. Please check the
archives, too.

Using schema, you must at least set the feature 

"http://apache.org/xml/features/validation/schema" 

with the method theParser.getXMLReader().setFeature(...). See
docs\features.html in the documentation. Furthermore, I recommend using URL
syntax for specifying the xsd: "file:///foo.xsd". Alternatively, you can use
an entity resolver for resolving foo.xsd or use the property 

"http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation"

with the method theParser.setProperty(...), for explicitly defining which
XSD to use.

Developers: since almost any1 using XSD the first time, seems to fall over
this issue, I would recommend putting it into the FAQ and providing an
example.

greetings
Heiner

-----Urspr√ľngliche Nachricht-----
Von: cruegger@speakeasy.net [mailto:cruegger@speakeasy.net]
Gesendet am: Montag, 4. November 2002 17:08
An: xerces-j-user@xml.apache.org
Betreff: problem using XML schema w/ Xerces 2


Situation:
I'm using Xerces 2.0 and trying to parse/validate
an XML document against a schema. Here are the xml and
schema files:

foo.xsd:
--------
<?xml version="1.0"?>
<xsd:schema
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  elementFormDefault="qualified">

<xsd:element name="request" type="requestType" />

<xsd:simpleType name="TF">
  <xsd:restriction base="xsd:string">
    <xsd:enumeration value="T" />
    <xsd:enumeration value="F" />
  </xsd:restriction>
</xsd:simpleType>

<xsd:complexType name="requestType">
  <xsd:sequence>
    <xsd:element name="clientID" type="xsd:string"/>
    <xsd:element name="password" type="xsd:string"/>
    <xsd:element name="flag"     type="TF"/>
  </xsd:sequence>
</xsd:complexType>
</xsd:schema>

foo.xml:
-------
<?xml version="1.0" encoding="UTF-8"?>
<request
  xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
  xsi:noNamespaceSchemaLocation='foo.xsd'>

<clientID>ABD</clientID>
<password>ABD</password>
<flag>Green</flag>
</request>

I create the Parser using JAXP, and the document handler interface:

SAXParserFactory parserFactory = SAXParserFactory.newInstance();
parserFactory.setNamespaceAware(true);
parserFactory.setValidating(true);
SAXParser theParser = parserFactory.newSAXParser();

I call parse passing an InputSource created from "foo.xml"
and and a class implementing the DefaultHandler interface.

Here is the eror I get:

error() LINE: 1
org.xml.sax.SAXParseException: Document is invalid: no grammar found.
error() LINE: 1
org.xml.sax.SAXParseException: Document root element "request", must match
DOCTYPE root "null".

Any ideas what I am doing wrong?
Thanks




---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Mime
View raw message