Search code examples
javadomxml-parsingsaxparser

Java SAX parsing of an XML String


I have a situation, where I get a string representation of an XML and I would like to parse it using SAX parser.

I know there is a way to use document builder in order to get a DOM document and parse it using DOM parser, but I would like to parse it using SAX.

I don't want to save it to a file and read it using the SAX parser, unless this is the only option.

What should I do in this situation?


Solution

  • Use SAXParser.parse(InputSource is, DefaultHandler dh) where

     InputSource is = new InputSource(new StringReader(str));