You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by "Petar Zhechev (JIRA)" <xe...@xml.apache.org> on 2006/03/16 15:12:58 UTC
[jira] Created: (XERCESJ-1146) Validator.validate incorrectly
reports "UndeclaredPrefix"
Validator.validate incorrectly reports "UndeclaredPrefix"
----------------------------------------------------------
Key: XERCESJ-1146
URL: http://issues.apache.org/jira/browse/XERCESJ-1146
Project: Xerces2-J
Type: Bug
Components: JAXP (javax.xml.validation)
Versions: 2.3.0
Environment: Microsoft Windows XP [Version 5.1.2600]
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode)
Reporter: Petar Zhechev
Xerces incorrectly reports ERROR: cvc-complex-type.2.2: Element 'soap-header' must have no element [children], and the value must be valid.
for a valid XML document. The problem appears only when you first get a DOM from XML and validate it with Validator.validate. If you validate the XML directly from StreamSource
the error message is not there. Please have a look at the provided source to reproduce the problem. If you comment the passage // 1 and uncomment the passage // 2 the
validation will pass fine.
import java.io.IOException;
import java.io.StringBufferInputStream;
import java.util.HashMap;
import java.util.LinkedHashMap;
import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
import org.w3c.dom.Document;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
public class Parse {
private static final String XML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ "<ejb-jar version=\"2.1\" xmlns=\"http://java.sun.com/xml/ns/j2ee\" xmlns:soap-header_ns__=\"http://extra-header.org\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd\">"
+ "<display-name>Ejb1</display-name>"
+ "<enterprise-beans>"
+ "<session>"
+ "<ejb-name>com_sun_ts_tests_common_vehicle_ejb_EJBVehicle</ejb-name>"
+ "<home>com.sun.ts.tests.common.vehicle.ejb.EJBVehicleHome</home>"
+ "<remote>com.sun.ts.tests.common.vehicle.ejb.EJBVehicleRemote</remote>"
+ "<ejb-class>com.sun.ts.tests.common.vehicle.ejb.EJBVehicle</ejb-class>"
+ "<session-type>Stateful</session-type>"
+ "<transaction-type>Container</transaction-type>"
+ "<service-ref>"
+ "<service-ref-name>service/SimpleTest</service-ref-name>"
+ "<service-interface>javax.xml.rpc.Service</service-interface>"
+ "<wsdl-file>META-INF/wsdl/SimpleTest.wsdl</wsdl-file>"
+ "<jaxrpc-mapping-file>SimpleTest.xml</jaxrpc-mapping-file>"
+ "<port-component-ref>"
+ "<service-endpoint-interface>com.sun.ts.tests.jaxrpc.wsi.w2j.rpc.literal.R2753.SimpleEndpoint</service-endpoint-interface>"
+ "</port-component-ref>"
+ "<handler>"
+ "<handler-name>Handler1</handler-name>"
+ "<handler-class>com.sun.ts.tests.jaxrpc.wsi.w2j.rpc.literal.R2753.R2753Handler</handler-class>"
+ "<soap-header xmlns:soap-header_ns__=\"http://extra-header.org\">soap-header_ns__:extra-header</soap-header>"
+ "<soap-role>extra-header-actor</soap-role>"
+ "</handler>"
+ "</service-ref>"
+ "<security-identity>"
+ "<use-caller-identity/>"
+ "</security-identity>"
+ "</session>"
+ "</enterprise-beans>"
+ "<assembly-descriptor>"
+ "<container-transaction>"
+ "<method>"
+ "<ejb-name>com_sun_ts_tests_common_vehicle_ejb_EJBVehicle</ejb-name>"
+ "<method-intf>Remote</method-intf>"
+ "<method-name>runTest</method-name>"
+ "</method>"
+ "<trans-attribute>Required</trans-attribute>"
+ "</container-transaction>" + "</assembly-descriptor>" + "</ejb-jar>";
private static HashMap XERCES_NONVALIDATING_ATTR = new LinkedHashMap();
public static void main(String[] args) throws SAXException, IOException,
ParserConfigurationException {
System.setProperty("http.proxyHost", "proxy");
System.setProperty("http.proxyPort", "8080");
SchemaFactory sf = SchemaFactory
.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema ejb21 = sf.newSchema(new StreamSource(
"http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd"));
Validator validator = ejb21.newValidator();
validator.setErrorHandler(new ErrorHandler() {
public void warning(SAXParseException exception) throws SAXException {
System.out.println("WARNING: " + exception.getMessage());
}
public void error(SAXParseException exception) throws SAXException {
System.out.println("ERROR: " + exception.getMessage());
}
public void fatalError(SAXParseException exception) throws SAXException {
System.out.println("FATAL_ERROR: " + exception.getMessage());
}
});
// 1 first get DOM, then validate
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setValidating(false);
dbf.setAttribute("http://xml.org/sax/features/validation", Boolean.FALSE);
dbf.setAttribute("http://apache.org/xml/features/nonvalidating/load-external-dtd", Boolean.FALSE);
dbf.setAttribute("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", Boolean.FALSE);
dbf.setAttribute("http://apache.org/xml/features/dom/defer-node-expansion", Boolean.FALSE);
dbf.setAttribute("http://apache.org/xml/features/dom/include-ignorable-whitespace", Boolean.FALSE);
dbf.setAttribute("http://apache.org/xml/features/nonvalidating/load-external-dtd", Boolean.FALSE);
dbf.setAttribute("http://xml.org/sax/features/namespaces", Boolean.TRUE);
DocumentBuilder nonValidating = dbf.newDocumentBuilder();
Document doc = nonValidating.parse(new InputSource(new StringBufferInputStream(XML)));
validator.validate(new DOMSource(doc));
// 2 directly validate
// validator.validate(new StreamSource(new StringBufferInputStream(XML)));
}
}
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: j-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-dev-help@xerces.apache.org
[jira] Resolved: (XERCESJ-1146) Validator.validate incorrectly
reports "UndeclaredPrefix"
Posted by "Michael Glavassevich (JIRA)" <xe...@xml.apache.org>.
[ http://issues.apache.org/jira/browse/XERCESJ-1146?page=all ]
Michael Glavassevich resolved XERCESJ-1146:
-------------------------------------------
Resolution: Invalid
Xerces doesn't have such a bug. Take a look at the stack trace of the exception you're catching. You'll likely find that the bug is in the JAXP implementation in JDK 5.0 (note the com.sun.org.* packages), not Xerces (which is org.apache.*):
org.xml.sax.SAXParseException: http://www.w3.org/TR/xml-schema-1#cvc-complex-type.2.2?soap-header
at com.sun.org.apache.xerces.internal.jaxp.validation.Util.toSAXParseException(Util.java:109)
at com.sun.org.apache.xerces.internal.jaxp.validation.ErrorHandlerAdaptor.error(ErrorHandlerAdaptor.java:104)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:382)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:316)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(XMLSchemaValidator.java:429)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.reportSchemaError(XMLSchemaValidator.java:3185)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.elementLocallyValidComplexType(XMLSchemaValidator.java:3153)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.elementLocallyValidType(XMLSchemaValidator.java:3121)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.processElementContent(XMLSchemaValidator.java:3025)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleEndElement(XMLSchemaValidator.java:2178)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.endElement(XMLSchemaValidator.java:814)
at com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl.endElement(ValidatorHandlerImpl.java:339)
at com.sun.org.apache.xml.internal.serializer.ToXMLSAXHandler.endElement(ToXMLSAXHandler.java:262)
at com.sun.org.apache.xml.internal.serializer.ToXMLSAXHandler.endElement(ToXMLSAXHandler.java:555)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:211)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:206)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:206)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:206)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:206)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:206)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:121)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:85)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(TransformerImpl.java:592)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:638)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:279)
at com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorImpl.process(ValidatorImpl.java:220)
at com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorImpl.validate(ValidatorImpl.java:141)
at javax.xml.validation.Validator.validate(Validator.java:82)
> Validator.validate incorrectly reports "UndeclaredPrefix"
> ---------------------------------------------------------
>
> Key: XERCESJ-1146
> URL: http://issues.apache.org/jira/browse/XERCESJ-1146
> Project: Xerces2-J
> Type: Bug
> Components: JAXP (javax.xml.validation)
> Versions: 2.3.0
> Environment: Microsoft Windows XP [Version 5.1.2600]
> java version "1.5.0_06"
> Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
> Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode)
> Reporter: Petar Zhechev
>
> Xerces incorrectly reports ERROR: cvc-complex-type.2.2: Element 'soap-header' must have no element [children], and the value must be valid.
> for a valid XML document. The problem appears only when you first get a DOM from XML and validate it with Validator.validate. If you validate the XML directly from StreamSource
> the error message is not there. Please have a look at the provided source to reproduce the problem. If you comment the passage // 1 and uncomment the passage // 2 the
> validation will pass fine.
> import java.io.IOException;
> import java.io.StringBufferInputStream;
> import java.util.HashMap;
> import java.util.LinkedHashMap;
> import javax.xml.XMLConstants;
> import javax.xml.parsers.DocumentBuilder;
> import javax.xml.parsers.DocumentBuilderFactory;
> import javax.xml.parsers.ParserConfigurationException;
> import javax.xml.transform.dom.DOMSource;
> import javax.xml.transform.stream.StreamSource;
> import javax.xml.validation.Schema;
> import javax.xml.validation.SchemaFactory;
> import javax.xml.validation.Validator;
> import org.w3c.dom.Document;
> import org.xml.sax.ErrorHandler;
> import org.xml.sax.InputSource;
> import org.xml.sax.SAXException;
> import org.xml.sax.SAXParseException;
> public class Parse {
> private static final String XML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
> + "<ejb-jar version=\"2.1\" xmlns=\"http://java.sun.com/xml/ns/j2ee\" xmlns:soap-header_ns__=\"http://extra-header.org\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd\">"
> + "<display-name>Ejb1</display-name>"
> + "<enterprise-beans>"
> + "<session>"
> + "<ejb-name>com_sun_ts_tests_common_vehicle_ejb_EJBVehicle</ejb-name>"
> + "<home>com.sun.ts.tests.common.vehicle.ejb.EJBVehicleHome</home>"
> + "<remote>com.sun.ts.tests.common.vehicle.ejb.EJBVehicleRemote</remote>"
> + "<ejb-class>com.sun.ts.tests.common.vehicle.ejb.EJBVehicle</ejb-class>"
> + "<session-type>Stateful</session-type>"
> + "<transaction-type>Container</transaction-type>"
> + "<service-ref>"
> + "<service-ref-name>service/SimpleTest</service-ref-name>"
> + "<service-interface>javax.xml.rpc.Service</service-interface>"
> + "<wsdl-file>META-INF/wsdl/SimpleTest.wsdl</wsdl-file>"
> + "<jaxrpc-mapping-file>SimpleTest.xml</jaxrpc-mapping-file>"
> + "<port-component-ref>"
> + "<service-endpoint-interface>com.sun.ts.tests.jaxrpc.wsi.w2j.rpc.literal.R2753.SimpleEndpoint</service-endpoint-interface>"
> + "</port-component-ref>"
> + "<handler>"
> + "<handler-name>Handler1</handler-name>"
> + "<handler-class>com.sun.ts.tests.jaxrpc.wsi.w2j.rpc.literal.R2753.R2753Handler</handler-class>"
> + "<soap-header xmlns:soap-header_ns__=\"http://extra-header.org\">soap-header_ns__:extra-header</soap-header>"
> + "<soap-role>extra-header-actor</soap-role>"
> + "</handler>"
> + "</service-ref>"
> + "<security-identity>"
> + "<use-caller-identity/>"
> + "</security-identity>"
> + "</session>"
> + "</enterprise-beans>"
> + "<assembly-descriptor>"
> + "<container-transaction>"
> + "<method>"
> + "<ejb-name>com_sun_ts_tests_common_vehicle_ejb_EJBVehicle</ejb-name>"
> + "<method-intf>Remote</method-intf>"
> + "<method-name>runTest</method-name>"
> + "</method>"
> + "<trans-attribute>Required</trans-attribute>"
> + "</container-transaction>" + "</assembly-descriptor>" + "</ejb-jar>";
> private static HashMap XERCES_NONVALIDATING_ATTR = new LinkedHashMap();
> public static void main(String[] args) throws SAXException, IOException,
> ParserConfigurationException {
> System.setProperty("http.proxyHost", "proxy");
> System.setProperty("http.proxyPort", "8080");
>
>
>
> SchemaFactory sf = SchemaFactory
> .newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
> Schema ejb21 = sf.newSchema(new StreamSource(
> "http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd"));
> Validator validator = ejb21.newValidator();
> validator.setErrorHandler(new ErrorHandler() {
> public void warning(SAXParseException exception) throws SAXException {
> System.out.println("WARNING: " + exception.getMessage());
> }
> public void error(SAXParseException exception) throws SAXException {
> System.out.println("ERROR: " + exception.getMessage());
> }
> public void fatalError(SAXParseException exception) throws SAXException {
> System.out.println("FATAL_ERROR: " + exception.getMessage());
> }
> });
>
> // 1 first get DOM, then validate
> DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
> dbf.setNamespaceAware(true);
> dbf.setValidating(false);
> dbf.setAttribute("http://xml.org/sax/features/validation", Boolean.FALSE);
> dbf.setAttribute("http://apache.org/xml/features/nonvalidating/load-external-dtd", Boolean.FALSE);
> dbf.setAttribute("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", Boolean.FALSE);
> dbf.setAttribute("http://apache.org/xml/features/dom/defer-node-expansion", Boolean.FALSE);
> dbf.setAttribute("http://apache.org/xml/features/dom/include-ignorable-whitespace", Boolean.FALSE);
> dbf.setAttribute("http://apache.org/xml/features/nonvalidating/load-external-dtd", Boolean.FALSE);
> dbf.setAttribute("http://xml.org/sax/features/namespaces", Boolean.TRUE);
> DocumentBuilder nonValidating = dbf.newDocumentBuilder();
> Document doc = nonValidating.parse(new InputSource(new StringBufferInputStream(XML)));
> validator.validate(new DOMSource(doc));
>
> // 2 directly validate
> // validator.validate(new StreamSource(new StringBufferInputStream(XML)));
> }
> }
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: j-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-dev-help@xerces.apache.org