This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Parsing of a String using DOM or SAX  RSS feed

 
parag Chatterjee
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have got the entire contents of a XML file in a String.

Is it possible to parse the XML from the String using DOM or SAX.
The problem is I am only having the string as the source and not any xml file.

Will highly appreciate any kind of help in this regard.

thanks,

Parag
 
Amit G Piplani
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Firstly construct InputSource as org.xml.sax.InputSource(new StringReader(String a)) and then parse this InputSource object as arguement to DocumentBuilder.parse(inputSource).

Hope it helps
 
Bajji Pat
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can do something like this:

byte bytearray[] = msgXML.getBytes();
ByteArrayInputStream bais = new ByteArrayInputStream(bytearray);
pa(i.e parserref).parse(new InputSource(bais));
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way, this is a FAQ.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!