2013-05-07 37 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

相關問題