|
Hi Demis, The following code worked for me. (relativeXsdFilePath is relative path to my schema file on the file system and xml is my instance document) I am using Xerces 2.0.0
I hope this helps you.
Puneet
try{
javax.xml.parsers.SAXParserFactory pf = javax.xml.parsers.SAXParserFactory.newInstance(); javax.xml.parsers.SAXParser sp = pf.newSAXParser(); org.xml.sax.XMLReader reader = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser"); reader.setFeature("http://xml.org/sax/features/validation",true); reader.setFeature("http://apache.org/xml/features/validation/schema",true); reader.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",relativeXsdFilePath); reader.setErrorHandler(this);
org.xml.sax.InputSource is = new org.xml.sax.InputSource(new StringReader(xml)); reader.parse(is);
System.out.println("Parsing finished");
}catch(Exception e) { System.out.println("Exception " + e.getMessage()); e.printStackTrace(); }
-----Original Message-----
Preliminary remarks: I'm a beginner!
I have tried to use XML Schema with Xerces 2.0.1 but I can't locate the xsd file on my file system.
I have read the XML Schema Limitations #usage, so this is the xsd (pattern.xsd):
<?xml version="1.0" encoding="utf-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> .... </xs:schema> and the xml file: <?xml version="1.0" encoding="utf-8"?> <PATTERN xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="pattern.xsd"> .... </PATTERN> Is it enough? Pattern.xsd is in the same directory with the xml file. This is the validation feature activation: try {
// Turn Schema Validation on When http://xml.org/sax/features/validation is true the error handler tell me that the element in the xml file must me declared. When http://xml.org/sax/features/validation is false the parser work ok but the schema is ignored (infact if I delete it, for the parser is the same thing).
I have tried to use namespace, for example: <document xmlns='http://my.com' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://my.com document.xsd'>...</document>
This email is confidential and intended solely for the use of the individual to whom it is addressed. Any views or opinions presented are solely those of the author and do not necessarily represent those of Zenesis Limited. If you are not the intended recipient, be advised that you have received this email in error and that any use, dissemination, forwarding, printing or copying of this email is strictly prohibited. If you have received this email in error please notify the administrator at Zenesis Limited, 20 Upper Maudlin Street, Bristol, BS2 8DJ, +44(0)117 9300789. Email [EMAIL PROTECTED]. |
- question: XML Schema location Demis Corvaglia
- Re: question: XML Schema location Puneet Narang
- Re: question: XML Schema location Rahul Srivastava
