cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

XML Parsing Issues

JeffStevenson
12-Amethyst

XML Parsing Issues

Hello everyone,


I feel like I've been posting a lot lately so excuse my newness to Windchill.


I have a Java package that is using Info Engine to extract information from WC. The pkg runs several tasks, one of which saves results to an external XML file. My process then walks through the XML file using DOM and extracts the appropriate files.


My problem is that it appears that the DOM parser in Java doesn't work the same running under Windchill as it does standalone or even under a separate Tomcat installation. I can confirm that the pkg is reading the XML file. But it appears to be unable to parse the XML under Windchill to give me the data I need from the XML file.


When I run the pkg as a standalone jar, it is fine. I included it into a servlet under a standalone Tomcat host and it ran fine there, too. So, I know it's not my package or Tomcat that are causing the issue.


Does anyone have any information about usingorg.w3c.dom and org.xml.sax.SAXException in the Windchill runtime?


Thanks!

5 REPLIES 5

Hello Jeff,

Probably you are running into xml skewed version problem .. There could be
a possibility that there are multiple parsers inside the Windchill
runtime..So, when you would run it standalone or a separate Tomcat
installation, it just works fine.

I did some xml stuff when I was re writing a similar utility like the
query builder and integrating an open source Business Intelligence tool.

I did not face any such problem then..Might be JAXP factories shielded me
from parser idiosyncracies .

How are creating a parser..

Best Regards

Shudh Datta

Shudh@shudh.me
——--------
Written on Droid

There's nothing magical here.

JAXP gives you different parsers in different environments based on
META-INF/services lookups, etc.

If you want a particular parser, then get it explicitly (and then use
normal JAXP APIs from thereon out).

What parser is being called under Windchill? I'm using DocumentBuilder with XPath to traverse the XML. This works in every other environment.

If you're using JAXP to get an XPath engine then you're quite likely
getting Saxon's. [Saxon is an XSLT 2.0 / XPath 2.0 engine.]

Hello Jeff,

You can try to take things outside JAXP's control and create parsers
explicitly as suggested by Jess...Say, creating a Xerces parser with
required support of W3C DOM ..

import org.apache.xerces.parsers.DOMParser;
DOMParser parser = new DOMParser();


If you need the Saxon parser then explicitly invoke that parser..(not sure
which one they use..)

As far as JAXP is concerned Sun's (Oracle..) strategy of using factory
classes tries to shield you from directly dealing with vendor specific XML
technologies. Your code that is failing in Windchill could be using the
following lines while creating parser..

DocumentBuilderFactory dbf =
DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();



This way of getting a parser relies on whichever XML parser is currently
set in the global variable or from certain files in classpath
(javax.xml.parsers.DocumentBuilderFactory system property).. The first line
creates a new DocumentBuilderFactory instance. By default, the
DocumentBuilderFactory uses the built-in XML parser that comes with JAXP,
but one can change the parser by setting the system property
javax.xml.parsers.DocumentBuilderFactory.

If you would like to use JAXP to get the parser then you may also set this
system property explicitly in your code using System.setProperty and unset
it after code execution is done..But this might not be a good approach as
this could change behavior and enforce JAXP to use the specific parser
mentioned in your changed property..Better approach would be to check if
you can pass a parameter to DocumentBuilderFactory to specify which XML
parser to use.

Finally, if you want to delve deeper on how JAXP is providing you with the
default parser..As per the JAXP docs JAXP looks in the lib/jaxp.properties
properties file in the JRE directory to determine a default value for the
javax.xml.parsers.DocumentBuilderFactory system property. If this fails to
locate a parser, next JAXP looks for a
META-INF/services/javax.xml.parsers.DocumentBuilderFactory file in all JAR
files available to the runtime to find the name of the
concreteDocumentBuilderFactory subclass.Finally, if that fails, then
DocumentBuilderFactory.newInstance() returns a default class..

Best Regards
Shudh



Announcements


Top Tags