This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes Parsing of a String using DOM or SAX Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Parsing of a String using DOM or SAX" Watch "Parsing of a String using DOM or SAX" New topic

Parsing of a String using DOM or SAX

parag Chatterjee

Joined: Aug 02, 2002
Posts: 28

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.


Amit G Piplani
Ranch Hand

Joined: Jul 21, 2004
Posts: 83
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

Joined: Apr 05, 2005
Posts: 50
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

Joined: Jan 23, 2002
Posts: 11962
By the way, this is a FAQ.

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Don't get me started about those stupid light bulbs.
subject: Parsing of a String using DOM or SAX