• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Finding the node value in XML

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 2108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Praveen, there's a set of useful examples at the Java Developer's Almanac on how to use the DOM API, for example.
 
reply
    Bookmark Topic Watch Topic
  • New Topic