Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create an org.xml.sax.InputSource from a String?

Tags:

java

xml

I am following a guide, and it gives me the following code:

InputSource inputSource = new InputSource(new FileInputStream(new File("/path/to/xml/file.xml"))));

What I would like to know, is how I can still create an org.xml.sax.InputSource, but instead of reading the content of a file, use a String variable that I already have.

like image 634
Chiggins Avatar asked Nov 25 '10 20:11

Chiggins


2 Answers

Use a StringReader instead of a FileInputStream.

See the documentation for StringReader

example:

InputSource inputSource = new InputSource( new StringReader( myString ) );
like image 72
Gavin H Avatar answered Oct 16 '22 03:10

Gavin H


InputSource inputSource = new InputSource(new java.io.StringReader(string)); if it is org.xml.sax.InputSource.

like image 38
khachik Avatar answered Oct 16 '22 01:10

khachik