Hi,
Is it possible to force validation against a specific local schema
regardless of the namespace/schemalocation in the instance document?
What I am trying to do is: If the web.xml used in an application is
higher than the version supported by the product, I am trying to force
validation against the highest supported version so that it doesn't
access the web to get the schema from the instance's schemalocation.
My web.xml has the following:
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
I want to validate it against a local web-app_2_4.xsd(with
targetnamespace of http://java.sun.com/xml/ns/j2ee). This schema can be
viewed at
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd
I have tried properties
http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation
http://apache.org/xml/properties/schema/external-schemaLocation
and turning off namespaceaware.
However, I am unable to get the desired result.
The source is:
public class MyParse extends DefaultHandler implements EntityResolver {
MyParse() {
try {
FileInputStream stream = new FileInputStream("web.xml");
URL url = new File("web.xml").toURL();
InputSource is = new InputSource(url.toExternalForm());
is.setByteStream(stream);
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
parserFactory.setNamespaceAware(false);
parserFactory.setValidating(true);
parserFactory.setFeature("http://apache.org/xml/features/validation/schema",
true);
parserFactory.setFeature("http://xml.org/sax/features/namespace-prefixes",
false);
parserFactory.setFeature("http://xml.org/sax/features/namespaces", false);
SAXParser parser = parserFactory.newSAXParser();
url = MyParse.class.getResource("web-app_2_4.xsd");
XMLReader xmlReader = parser.getXMLReader();
StringBuffer sb = new StringBuffer(200);
sb.append("http://java.sun.com/xml/ns/javaee ");
sb.append(url.toString());
// Setting these properties does not get the desired result
//
xmlReader.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation",
sb.toString());
//xmlReader.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",
url.toString());
xmlReader.setErrorHandler(this);
xmlReader.setEntityResolver(this);
xmlReader.parse(is);
} catch (Exception e) {System.out.println("Exception e = "+e); }
}
Thanks
-Uma
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]