【问题标题】:How do I create an org.xml.sax.InputSource from a String?如何从字符串创建 org.xml.sax.InputSource?
【发布时间】:2010-11-25 20:49:50
【问题描述】:

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

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

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

【问题讨论】:

    标签: java xml


    【解决方案1】:

    使用StringReader 而不是FileInputStream

    请参阅StringReader 的文档

    示例:

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

    【讨论】:

    • 工作就像一个魅力。谢谢老兄。
    【解决方案2】:

    InputSource inputSource = new InputSource(new java.io.StringReader(string)); 如果是org.xml.sax.InputSource

    【讨论】:

      猜你喜欢
      • 2011-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-24
      • 2016-11-13
      相关资源
      最近更新 更多