According to the Xerces-J docs, if the http://apache.org/xml/features/validation/dynamic feature is false, validation is determined by the state of the http://xml.org/sax/features/validation feature. Try setting http://apache.org/xml/features/validation/dynamic to false (or just don't set it, the default is false), then the validation should work fine.
Ivan -----Original Message----- From: Tung Mansfield [mailto:[EMAIL PROTECTED] Sent: Friday, May 04, 2001 6:37 PM To: [EMAIL PROTECTED] Subject: validation I was trying out the schema validation feature of xerces 1.3.1, but it does not work for me. Can somebody tell me what I am doing wrong? Here is my code: public class TestXML { public static void main(String[] args) throws Exception { String fileName = "c:/temp/test.xml"; FileInputStream stream = new FileInputStream(fileName); DOMParser parser = new DOMParser(); parser.setFeature("http://xml.org/sax/features/validation", true); parser.setFeature("http://apache.org/xml/features/validation/schema", true); parser.setFeature("http://apache.org/xml/features/validation/dynamic", true); parser.setFeature("http://xml.org/sax/features/namespaces", true); parser.setErrorHandler(new MyErrorHandler()); errHandler = parser.getErrorHandler(); parser.parse(new InputSource(stream)); } } class MyErrorHandler implements ErrorHandler { public void error(SAXParseException exception) throws SAXException { exception.printStackTrace(); } public void warning(SAXParseException exception) throws SAXException { exception.printStackTrace(); } public void fatalError(SAXParseException exception) throws SAXException { exception.printStackTrace(); } } Here are my xml and schema files: <Root xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance" xsi:noNamespaceSchemaLocation='test.xsd'> <A/> <B/> <bad/> </Root> <xsd:schema xmlns:xsd="http://www.w3.org/2000/10/XMLSchema" elementFormDefault="qualified"> <xsd:element name="Root"> <xsd:complexType> <xsd:sequence> <xsd:element name="A"/> <xsd:element name="B"/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema> When I validate the XML through XMLSpy, it correctly report the error with the "bad" element. But Xerces did not report any error. Thanks for your help. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] This message is for the named person's use only. It may contain confidential, proprietary or legally privileged information. No confidentiality or privilege is waived or lost by any mistransmission. If you receive this message in error, please immediately delete it and all copies of it from your system, destroy any hard copies of it and notify the sender. You must not, directly or indirectly, use, disclose, distribute, print, or copy any part of this message if you are not the intended recipient. CREDIT SUISSE GROUP and each of its subsidiaries each reserve the right to monitor all e-mail communications through its networks. Any views expressed in this message are those of the individual sender, except where the message states otherwise and the sender is authorised to state them to be the views of any such entity. Unless otherwise stated, any pricing information given in this message is indicative only, is subject to change and does not constitute an offer to deal at any price quoted. Any reference to the terms of executed transactions should be treated as preliminary only and subject to our formal written confirmation. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
