aspose file tools*
The moose likes XML and Related Technologies and the fly likes javax.xml.validation.Validator.validate(DOMSource) works in tomcat, but fails in Websphere Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "javax.xml.validation.Validator.validate(DOMSource) works in tomcat, but fails in Websphere" Watch "javax.xml.validation.Validator.validate(DOMSource) works in tomcat, but fails in Websphere" New topic
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
Shiva Mannem
Greenhorn

Joined: Jun 18, 2013
Posts: 2
i am also facing the same issue, please help me out if you got the solution already..
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 535
    
    3
i am also facing the same issue...

So you're facing the same issue... But the original post displays a completely broken schema, it can't possibly work with any compliant validating parser, in whatever setup including tomcat (a contradiction to the original announcement of the problem). Maybe you should post your own question in a thread of your own.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: javax.xml.validation.Validator.validate(DOMSource) works in tomcat, but fails in Websphere