Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to pasrse XML string quickly in java

 
srihari paturi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Could you please tell me how to parse xml string in java.
Ex. I have a string like this
String str ="<A><b>10</b>
<C><c>hai</c></C>
</A>
how to get the values of it?

Thanks
 
Freddy Wong
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use SAX or DOM for that. DOM is easier to use than SAX. You can also you dom4j, which is easier than the normal DOM.

Do some google search. There are lot of tutorials on how to parse XML using DOM or SAX.

Good luck.
 
Kamal Ahmed
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance();

DocumentBuilder dBuilder = dFactory.newDocumentBuilder();

Document doc = dBuilder.parse(new InputSource(new StringReader("<test>test</test>")));
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic