2
研究Java读/写Java/SAX,我发现只处理磁盘文件的例子 - 我需要STRING输入/输出处理。我使用XML输入/输出编码WebService,所以我需要处理STRING XML,而不是文件。Java WebService:字符串XML SAX读/写,而不是通过文件
谢谢。
研究Java读/写Java/SAX,我发现只处理磁盘文件的例子 - 我需要STRING输入/输出处理。我使用XML输入/输出编码WebService,所以我需要处理STRING XML,而不是文件。Java WebService:字符串XML SAX读/写,而不是通过文件
谢谢。
这个例子是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
。有点冗长,但有效。
这是你想要的吗?是否足以展示如何继续?如果没有,你可以发布你的当前代码文件吗? – 2013-05-08 13:21:17