This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Parsing of a String using DOM or SAX

 
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