wood burning stoves 2.0*
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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
Author

Parsing of a String using DOM or SAX

parag Chatterjee
Greenhorn

Joined: Aug 02, 2002
Posts: 28
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

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


SCJP,SCWCD,SCBCD,SCDJWS1.4, SCDJWS1.5
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
author
Sheriff

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


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Parsing of a String using DOM or SAX
 
Similar Threads
parsing XML
Pretty printing XML
DOM and SAX
Parsing XML string using Java Program
parsing Html