|
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> Probably I'm very silly but I can't understand: if the xsd is on my file system instead of http://my.com what have I to write? After a lot of attempt, I have discovered the parser
properties: http://apache.org/xml/properties/schema/external-schemaLocation and http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation.
So:
String id = "http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation";
String value = "pattern.xsd"; try { parser.setProperty(id, value); } catch (SAXException e) { System.err.println("could not set parser properties " + e.getMessage()); } ... but this produce an exception!! (in the DOM parser and in
the SAX parses as well).
What can I do?
These are very stupid question I know, but there aren't
tutorial or manual where to learn Xerces usage (or I can't find
it).
Thank you.
Demis.
|
- RE: question: XML Schema location Demis Corvaglia
- RE: question: XML Schema location Puneet Narang
- Re: question: XML Schema location Rahul Srivastava
