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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Gesendet am: Montag, 4. November 2002 17:08 An: [EMAIL PROTECTED] 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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
