Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Sunil Garg   on Jul 28 In Java Category.

  
Question Answered By: Joyce Edwards   on Jul 28

You need an xml  parser. You can either go with a
low-level parser such as Xerces or Crimson
(http://xml.apache.org/) or
something a little bit higher level such as
JDOM (http://www.jdom.org/) or Dom4J
(http://www.dom4j.com/). The nice
thing about JDOM and Dom4J is that they
create Java object models which are easier to work with
than the DOM or SAX models that lower-level parsers
produce.For example, using Dom4J you would find a value like
this:SAXReader reader = new SAXReader();Document document =
reader.read(new FileInputStream("file.xml"));Element
rootElement = document.getRootElement();That would
give you the root element  - then you can walk the XML
tree to find the element you want:Element
element = rootElement.getChild("firstChild");String
text = element.getText();There are also other
ways such as XPath, but you will need to look at that
on your own. Take a look at Dom4J or JDOM - trust me
when I say that it makes dealing with XML documents
easy.

Share: 

 
 
Didn't find what you were looking for? Find more on Read element from XML Or get search suggestion and latest updates.


Tagged: