-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

2
  • 7
    Step 1) try it yourself, step 2) if you have issues then come back and ask a specific question... Commented Nov 29, 2012 at 7:26
  • Also use the exact xml file because it has few errors in your xml file . Commented Nov 29, 2012 at 7:31

4 Answers 4

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

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

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

Comments

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.