Thursday, November 17, 2005

Java : String input to Digester

Every one of the gazillion examples out there use an XML file to demonstrate how to use Digester.

But what if you need to hand Digester some XML which is actually a String input.

Problem! The only String constructor needs a URI.

Well, you could write it to a file and then use the File constructor as input.

Yeah - right!

Use the StringReader class which converts a string to an input stream e.g.

StringReader sReader = new StringReader (AXmlString);
myResponse = (Response) digester.parse (sReader);

Enjoy!

No comments: