-3

I have an XML, for example

<root>
 <config x="xxx" y="yyyy" z="zzz" />
 <properties>blah blah blah </properties>   
 <example>
   <name>...</name>
   <decr>...</descr>
 </example> 
 <example>
   <name>...</name>
   <decr>...</descr>
 </example> 
</root>

and I need to get nodes config, and properties and all values in it. Thank you

dummy
  • 63
  • 9

4 Answers4

2

Xpath can fetch you the data in the config tag. You need to create an expression first like this expression="//root/config/@x", to get value of x,y,z. For properties, follow this thread : Parsing XML with XPath in Java

Hope this helps

Community
  • 1
  • 1
SmartCoder
  • 21
  • 2
1

DOM,DOM4J,SAX..

if the size of XML file is small,you can use DOM or DOM4J,but the size is big , you use the SAX

SongGuang
  • 71
  • 2
1

If you directly want to query or fetch data XPath can help, but if you want the data as Java Objects so that you can use it further then use JAXB

Narendra Pathai
  • 41,187
  • 18
  • 82
  • 120
0

You can use SAX parser to read the xml manipulate its event based parsing and consumes more memory. If your xml is big and requires lot of manipulations then go-for DOM/DOM4j either is good. DOM4L is very latest. DOM is widely used in industry.

Based on your requirement go for good parser.

Thanks, Pavan

Pavan
  • 1,219
  • 13
  • 15