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

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