Skip to main content

javax.xml.validation.Validator.validate(DOMSource) works in tomcat, but fails in Websphere

No replies
Lokesh_Rao
Offline
Joined: 2012-02-09
Points: 0

Hi

I am using IBM Java 1.6 on Websphere. I am validating an xml using an xsd, the sample code works fine when deployed in tomcat, but in WAS8.0. its unable to declaration of my root element. sample code and error follows, has anyone faced similar problem with IBM Java, the surprising part it works very well with sun jdk.

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)