• Post Reply Bookmark Topic Watch Topic
  • New Topic

XML Parser  RSS feed

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

I am trying to implement a application using the SAX Parser. I can do this just fine if the XML input is a file. Is there a way to do this passing that function a XML-formatted string?

If that doesn't make sense, I can try to explain better.

Thanks,
Stephen
 
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you can do this easily. The key is that the "InputSource" class can be constructed from a java.io.Reader. To parse XML from a String, use a java.io.StringReader to source the data:

SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
InputSource source = new InputSource(new StringReader(myXMLString));
parser.parse(source, mySAXHandler);
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!