| Author |
Finding the node value in XML
|
praveen kumar
Greenhorn
Joined: Sep 12, 2005
Posts: 9
|
|
Hello, I have xml file in the format(where "<" replaced with < and ">" replaced with > format and '"' replaced with " I am a newbie to java program Now my problem is to find the value of a particular node?, so how can I parse this xml to find the vale of a node. ---XML FILE--- <transmission_info> <mechanism value="fax"/> <fax_info> <transmit_info> <faxno value="11111111"/> <cover_text value="Please process this order in a timely manner."/> <retries value="3"/> <wait value="300"/> </transmit_info> </fax_info> </transmission_info> -----END------- For example say: Find the vale of (fax no) from the above XML. Regards Praveen
|
 |
Jesus Angeles
Ranch Hand
Joined: Feb 26, 2005
Posts: 2036
|
|
Unless you want to create your own parser technology, you are most likely looking for SAX, or DOM. SAX and DOM work differently but will serve your need. There are free implementations of these parsers. Try find in apache website. Also, Java has JAXP, which is an API for SAX, DOM and others.
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12265
|
|
The XML classes in Java 1.4 and 1.5 can do this, no need to get another library. There are plenty of tutorials on the web. Unless your XML input document is huge, parsing into a DOM Document will be the simplest approach. Bill
|
Java Resources at www.wbrogden.com
|
 |
Lasse Koskela
author
Sheriff
Joined: Jan 23, 2002
Posts: 11962
|
|
|
Praveen, there's a set of useful examples at the Java Developer's Almanac on how to use the DOM API, for example.
|
Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
|
 |
 |
|
|
subject: Finding the node value in XML
|
|
|