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

JavaXml

Java Problem Overview


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.

Java Solutions


Solution 1 - Java

Use a StringReader instead of a FileInputStream.

See the documentation for StringReader

example:

InputSource inputSource = new InputSource( new StringReader( myString ) );

Solution 2 - Java

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionChigginsView Question on Stackoverflow
Solution 1 - JavaGavin HView Answer on Stackoverflow
Solution 2 - JavakhachikView Answer on Stackoverflow