DOM parser throws exception doing XML Schema Validation
843834Jun 21 2002 — edited Jun 24 2002Hi, I have problems with validation of xml.
I try to validate a Xml document that is actually a Soap message envelope. This is my message:
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/" env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<env:Body>...</env:Body>
</env:Envelope>
And this is my java code to parse Xml document:
static final String JAXP_SCHEMA_LANGUAGE =
"http://java.sun.com/xml/jaxp/properties/schemaLanguage";
static final String W3C_XML_SCHEMA =
http://www.w3.org/2001/XMLSchema;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setValidating(true);
dbf.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
dbf.setAttribute(
"http://apache.org/xml/properties/schema/external-schemaLocation",
"http://schemas.xmlsoap.org/soap/envelope/ http://schemas.xmlsoap.org/soap/envelope/");
DocumentBuilder domBuilder = dbf.newDocumentBuilder();
System.out.println("parsing xml document...");
domBuilder.parse("file:/C:/tmp/soapMsg.xml");
I have this exception:
Warning: validation was turned on but an org.xml.sax.ErrorHandler was not
set, which is probably not what is desired. Parser will use a default
ErrorHandler to print the first 10 errors. Please call
the 'setErrorHandler' method to fix this.
Error: URI=file:/C:/tmp/soapMsg.xml Line=11: cvc-complex-type.3.2.2: Attribute 'env:encodingStyle' is not allowed to appear in element 'env:Envelope'.
Parser says that attribute env:encodingStyle is not allowed... why? I looked at envelope schema and there is an element <xs:anyAttribute...> in envelope complex type, so it would be ok... so why does parser say me that attribute is not allowed? is it a bug?