Good day everybody.
There is some strange things with xerces when i'm trying to validate attached file "test.xml", defined with "test.xsd" (also attached):
I can instanciate org.apache.xerces.parsers.DOMParser, set the features and parse file:
---
import org.apache.xerces.parsers.DOMParser;
...
DOMParser domParser = new DOMParser();
domParser.setFeature("http://xml.org/sax/features/validation", true);
domParser.setFeature("http://apache.org/xml/features/validation/schema", true); domParser.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true);
domParser.parse("test.xml");---
and everything will be o'key, but if i want to use javax.xml.parsers.DocumentBuilderFactory and javax.xml.parsers.DocumentBuilder as follows:
---
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilder;
...
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setAttribute("http://xml.org/sax/features/validation", new Boolean(true));
documentBuilderFactory.setAttribute("http://apache.org/xml/features/validation/schema", new Boolean(true));
documentBuilderFactory.setAttribute("http://apache.org/xml/features/validation/schema-full-checking", new Boolean(true));
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
documentBuilder .parse("test.xml");---
then I'll get an instances of org.apache.xerces.jaxp.DocumentBuilderFactoryImpl (correct) and org.apache.xerces.jaxp.DocumentBuilderImpl (correct) (with org.apache.xerces.parsers.DOMParser inside with correctly setted features) and an error: "[Error] test.xml:6:62: cvc-elt.1: Cannot find the declaration of element 'myns:root'." (wrong!).
Tell me, please, where i'm wrong.
Thanks a priori.
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
xmlns:myns="http://any.namespace.there"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://any.namespace.there"
elementFormDefault="qualified"
attributeFormDefault="qualified">
<xs:element name="root" type="xs:string"/>
</xs:schema>
<?xml version="1.0" encoding="UTF-8"?>
<myns:root
xmlns:myns="http://any.namespace.there"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://any.namespace.there test.xsd">
Sample.
</myns:root>
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
