2013-05-07 38 views

回答

0

这个例子是Xerces的,最有名的XML的Java解析器之一: 见http://xerces.apache.org/xerces2-j/javadocs/api/org/xml/sax/XMLReader.html

parse 

void parse(InputSource input) 
      throws java.io.IOException, 
        SAXException 

    Parse an XML document. 

    The application can use this method to instruct the XML reader 
to begin parsing an XML document from any valid input source 
(a character stream, a byte stream, or a URI). 

您必须创建一个InputSource这可以从各种来源的多样性,包括字符(字符串)。

http://xerces.apache.org/xerces2-j/javadocs/api/org/xml/sax/InputSource.html

public InputSource(java.io.InputStream byteStream) 

    Create a new input source with a byte stream. 





    Application writers should use setSystemId() to provide a base for 
resolving #relative URIs, may use setPublicId to include a public 
identifier, and may use setEncoding to specify the object's character encoding. 

您可能会发现,你的XML工具有替代品,包括InputStream。如果是这样,您可以使用从您的字符串形成的ByteArrayInputStream。有点冗长,但有效。

+0

这是你想要的吗?是否足以展示如何继续?如果没有,你可以发布你的当前代码文件吗? – 2013-05-08 13:21:17

相关问题