如何从字符串创建 org.xml.sax.InputSource?

问题描述:

我正在遵循指南,它给了我以下代码:

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"))));

我想知道的是,我仍然可以创建 org.xml.sax.InputSource,但不是读取文件的内容,而是使用 String代码>我已经拥有的变量.

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.

使用 StringReader 而不是 FileInputStream.

请参阅StringReader

示例:

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