Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert the string content into an XMLStreamReader

Tags:

java

Hi I would like to know how we can convert the string content which is in the form of XML tag and I need to convert it into XMLStreamReader

like image 252
user2767404 Avatar asked Sep 11 '13 05:09

user2767404


1 Answers

You can use XMLInputFactory.createXMLStreamReader, passing in a StringReader to wrap your string.

String text = "<foo>This is some XML</foo>";
Reader reader = new StringReader(text);
XMLInputFactory factory = XMLInputFactory.newInstance(); // Or newFactory()
XMLStreamReader xmlReader = factory.createXMLStreamReader(reader);
like image 84
Jon Skeet Avatar answered Oct 20 '22 17:10

Jon Skeet