How to create org.xml.sax.InputSource from a string?

I follow the guide and it gives me the following code:

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

I would like to know how I can create org.xml.sax.InputSource , but instead of reading the contents of the file, use the String variable that I already have.

+44
java
Nov 25 '10 at 20:49
source share
2 answers

Use StringReader instead of FileInputStream .

See the documentation for StringReader

Example:

 InputSource inputSource = new InputSource( new StringReader( myString ) ); 
+75
Nov 25 '10 at 20:53
source share

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

+3
Nov 25 '10 at 20:55
source share



All Articles