| Author |
javax.xml.validation.Validator.validate(DOMSource) works in tomcat, but fails in Websphere
|
Lokesh Rao
Greenhorn
Joined: Feb 09, 2012
Posts: 1
|
|
Hi
I have developed a small program which validates an xml against an xsd, I am using SchemaFactory and DocumentBuilderFactory. I parse the xml file and create an w3c dom, i use schema.newValidator() and validate the DOM. It works perfectly in tomcat, but the same fails in WAS. Sample Code and error is below, The behavior is very strange , am i missing some thing basic here when it comes to xerces api. i see the package difference between sun and ibm jdk
Note: setNamespaceAware is done, no setting are done using System.setProperty("javax.xml.parsers.DocumentBuilderFactory","org.apache.xerces.jaxp.DocumentBuilderFactoryImpl")) for WAS(jaxp.properties)
Sample Code
schemaFactory=SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
domBuilderFac=DocumentBuilderFactory.newInstance();
docBuilder=domBuilderFac.newDocumentBuilder();
domBuilderFac.setNamespaceAware(true);
org.w3c.dom.Document document=docBuilder.parse(new FileInputStream(new File(xmlFilePath)));
InputStream is=getClass().getClassLoader().getResourceAsStream("GL.xsd");
System.out.println("Got the XSD "+is.available());
Source source=new StreamSource(is);
schema=schemaFactory.newSchema(source);
Validator validator=schema.newValidator();
System.out.println("Inside the validateXML: "+validator.getClass());
validator.validate(new DOMSource(document));
XSD:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="GeneralLibrary">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" ref="GeneralClass"/>
</xs:sequence>
<xs:attribute name="Title" use="required" type="xs:string"/>
<xs:attribute name="description" use="required"/>
<xs:attribute name="Name" use="required" type="LimitedString"/>
<xs:attribute name="Owner" use="required" type="LimitedString"/>
<xs:attribute name="type" use="required" fixed="General Library"/>
<xs:attribute name="Vault" use="required" type="LimitedString"/>
<xs:attribute name="state" use="required" type="LimitedString"/>
</xs:complexType>
</xs:element>
</xs:schema>
XML
<GeneralLibrary xmlns:xs="http://www.w3.org/2001/XMLSchema" Name="GLIB54321" type="General Library" description="GLIB11" Title="GLIB11" Vault="aa" Owner="bb" state="cc"></GeneralLibrary>
Error
org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'GeneralLibrary'.
[2/9/12 13:12:53:941 GMT+05:30] 00000019 SystemErr R at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
[2/9/12 13:12:53:941 GMT+05:30] 00000019 SystemErr R at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
[2/9/12 13:12:53:941 GMT+05:30] 00000019 SystemErr R at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
[2/9/12 13:12:53:941 GMT+05:30] 00000019 SystemErr R at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
[2/9/12 13:12:53:941 GMT+05:30] 00000019 SystemErr R at org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source)
[2/9/12 13:12:53:941 GMT+05:30] 00000019 SystemErr R at org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(Unknown Source)
[2/9/12 13:12:53:941 GMT+05:30] 00000019 SystemErr R at org.apache.xerces.jaxp.validation.DOMValidatorHelper.beginNode(Unknown Source)
[2/9/12 13:12:53:941 GMT+05:30] 00000019 SystemErr R at org.apache.xerces.jaxp.validation.DOMValidatorHelper.validate(Unknown Source)
[2/9/12 13:12:53:941 GMT+05:30] 00000019 SystemErr R at org.apache.xerces.jaxp.validation.DOMValidatorHelper.validate(Unknown Source)
[2/9/12 13:12:53:941 GMT+05:30] 00000019 SystemErr R at org.apache.xerces.jaxp.validation.ValidatorImpl.validate(Unknown Source)
[2/9/12 13:12:53:941 GMT+05:30] 00000019 SystemErr R at javax.xml.validation.Validator.validate(Unknown Source)
Experts on this forum, can you please guide me what the fix for this problem on WAS
|
 |
 |
|
|
subject: javax.xml.validation.Validator.validate(DOMSource) works in tomcat, but fails in Websphere
|
|
|