File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes XML Parsing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "XML Parsing" Watch "XML Parsing" New topic

XML Parsing

Jomy George
Ranch Hand

Joined: Jan 13, 2011
Posts: 68
Hi Friends

It’s about xml parsing. I need to handle an xml document like this.

For retrieving <type> value I am using a method as below.

As this is a frequently using code in application, I would like to know if there any better way to do the same.

Thanks in advance…
Claudiu Chelemen
Ranch Hand

Joined: Mar 25, 2011
Posts: 73

Lately I find it nauseous to do the xml parsing manually, so I referred to an automated data binding solution, Castor, but I'm sure there are similar solutions around (jaxb?).

The advantage is that once you get to map the xml to a java bean, it renders your job very easy to marshall/unmarshall objects.
Afterwards, to get the needed value, you only have to call the respective getter on the bean.

Jomy George
Ranch Hand

Joined: Jan 13, 2011
Posts: 68
Hi Claudiu Chelemen,

But I am not allowed to use any data binding tools like Castor. Need to handle it manually.
Thanks for your quick reply...
Rob Spoor

Joined: Oct 27, 2005
Posts: 20183

Check out XPath.

How To Ask Questions How To Answer Questions
subject: XML Parsing
It's not a secret anymore!