wood burning stoves 2.0*
The moose likes XML and Related Technologies and the fly likes parsing and displaying xml data - options? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "parsing and displaying xml data - options?" Watch "parsing and displaying xml data - options?" New topic

parsing and displaying xml data - options?

Raj Murthy

Joined: Oct 25, 2005
Posts: 14
Hello All,

We are working on a system that will get xml feed (through webservice or some other means.. to be decided) and display the results on a browser.

The platform is weblogic 8.1.3, we need to decide on the xml libraries to be used for parsing and displaying of a data, though weblogic offers certain jars for xml based processing we are thinking something more open source would be helpful incase we need to move the code to a different platform.

We are considering apache xerces.jar (for parsing the xml data), with xslt and xalan.jar for the transformations to convert it into html?

What is the latest/best versions of these two?

What are the alternatives to xerces and xalan, if any?

Any inputs on this will be greatly appreciated.

Ulf Dittmer

Joined: Mar 22, 2005
Posts: 41108
The latest versions of Xerces and Xalan are at xml.apache.org.

Alternatives would be Suns Crimson for XML and Saxon (on SourceForge) for XSLT.

You'll probably be fine using the Weblogic parser, whichever it is. Just make sure that you code against the JAXP API (which is the Java XML/XSLT/DOM/SAX processing API), and not against classes that may be specific to a particular parser. Then you should have no problems moving your code to use some other parser, because they all support JAXP.

Ping & DNS - my free Android networking tools app
Raj Murthy

Joined: Oct 25, 2005
Posts: 14
Thanks for your response.


I am able to read xml, apply xsl and convert it to html.
I have included the code below.



Couple of notes on the same:

1. I am creating a new StreamReader from string to pass to transform method, not sure
if this is the most efficient way?

2. Rather than write to file, need to return the transform output as a String.

3. I can possibly optimize the xslSource by creating it only once, since this method will be called multiple times, sometimes possibly in a concurrent manner?

Any hints?

Ulf Dittmer

Joined: Mar 22, 2005
Posts: 41108
#1) You could use a BufferedReader instead, but since all data is in memory already, I wouldn't expect a noticeable difference.

#2) You can pass a StringWriter to the StreamResult constructor.

#3) Check out javax.xml.transform.Templates (use TransformerFactory.newTemplates instead of TransformerFactory.newTransformer). It facilitates caching of XSLT transformations, and also guarantees thread-safety.
[ October 26, 2005: Message edited by: Ulf Dittmer ]
Raj Murthy

Joined: Oct 25, 2005
Posts: 14
Thanks for your suggestions.

Here is the modified code(for anyone interested):

Not to prolong this thread, what if i use a JDOMSource instead of streamsource will it help the performance?
Since the calling program has the liberty of passing either xml-string of jdom source.

>>JDOMSource source = new JDOMSource(sourceDoc);


>>StreamSource s1 = new StreamSource(new ByteArrayInputStream(strXml.getBytes()));

JuanP barbancho
Ranch Hand

Joined: Oct 25, 2005
Posts: 52

Let to your administrator the use of parser and use JAXP api.

You weblogic administrator could change the parser and use the fastest that Bea say
Raj Murthy

Joined: Oct 25, 2005
Posts: 14
Thanks. Will give that a try.
[ October 28, 2005: Message edited by: Rajiv Rangarajan ]
Don't get me started about those stupid light bulbs.
subject: parsing and displaying xml data - options?
Similar Threads
Can we store the data from data base to a XML file and avoid contacting data base
db to java to xml
Regarding the xml generation of the japanese data
XML parsing
Parsing data file to XML?