XML Parser

Hey guys, this is the scenario, I have a JSP website, that is making a SOAP call to a C# component, this component will return some XML as you know.. and i want the java to read this file, should I go ahead and write my own parser or are there any decent parsers out there for XML that are highly custumizable

thanks!

tony

[341 byte] By [jacunara] at [2007-10-2 22:24:53]
# 1

This problem seems to be quite standard.

1. Simple Path - refer to XMLBeans - I guess ultimately you want java objects. XMLBeans can do this for you easily.

2. Complex Path - write your own code to parse the data (guess you'll use SAX), use any decent parser (I use picollo which they claim to be the fastest) and create your java objects.

In path 2, you can do lot of customization and optimization. Risk of overdoing also is high.

debajyotibanerjeea at 2007-7-14 1:42:17 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2
thanks, I have decided to go with JDOM but aparently i can only parse files and not string which is disapointing
jacunara at 2007-7-14 1:42:17 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3
JAXP is a good option for xml parsing.. Also, it is implementation neutral and hence tomorrow u can go with any JAXP- compliant parser.. for example, xerces.Also, JAXP has parse APIs for parsing String.. You have to use StringReader coupled with parse(Source)
senthilkumar_ksa at 2007-7-14 1:42:17 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4
I use piccolo which they claim is faster. Refer to http://piccolo.sourceforge.net/bench.html
debajyotibanerjeea at 2007-7-14 1:42:17 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 5

This string reader sounds interesting, would you be so kind as to post a little code snippet to see how it works? Im on a trip right now so I dont have a JDK :( but I at least want to imagine what im going to do on monday. Also, thanks for the piccolo tip, i will be researching that

thanks!

jacunara at 2007-7-14 1:42:17 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 6

Here we go..

package xml;

import javax.xml.parsers.SAXParserFactory;

import javax.xml.parsers.SAXParser;

import org.xml.sax.helpers.DefaultHandler;

import org.xml.sax.Attributes;

import org.xml.sax.InputSource;

import java.io.StringReader;

public class SAXReader extends DefaultHandler

{

private static final String instanceDoc ="<persons><person><name>Senthil</name></person></persons>";

public SAXReader() throws javax.xml.parsers.ParserConfigurationException,org.xml.sax.SAXException, java.io.IOException

{

SAXParserFactory saxFactory = SAXParserFactory.newInstance();

SAXParser parser = saxFactory.newSAXParser();

parser.parse(new InputSource(new StringReader(instanceDoc)),this);

}

public static void main(String[] args) throws javax.xml.parsers.ParserConfigurationException,org.xml.sax.SAXException, java.io.IOException

{

new SAXReader();

}

public void startElement(String uri, String localName, String qName, Attributes attributes)

{

System.out.println(qName);

}

}

senthilkumar_ksa at 2007-7-14 1:42:17 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 7
thanks so much! works great.!!!!!!!!hurray!:)
jacunara at 2007-7-14 1:42:17 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 8

Hi.

I'm reading the J2EE tutorial 1.4 (old version respect of J2EE Enterprise Edition 5 tutorial)...

I have made a practice of this book about refered to JAXP/SAXParser,

and it throws an exception at runtime and it's perfectly coded.

this tutorial says that a library is necessary to run the program OUT of Application Server, (<JAVAHOME>/JRE/LIB/ENDORSED)...?

I supose that the error comes from ausences of this library.

And I dont have this library installed in the directory that the tutorial mencioned. and I have installed the J2EE "5" perfectly. and the problem goes on....

Are there any changes between J2EE 1.4 tutorial and J2EE 5 tutorial related to its technology?

I need some help, how can I solve this problem?...

Regards

Patricio.

DTDsa at 2007-7-14 1:42:17 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...