我在变量中有xml文档(不在文件中)。如何在其中存储数据?我没有任何额外的文件,我把它放在我的源码里。当我使用
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(XML);(XML是我的xml变量),我得到一个错误
java.io.FileNotFoundException: C:\netbeans\app-s7013\<network ip_addr="10.0.0.0\8" save_ip="true"> File not found.发布于 2010-06-16 08:44:25
将XML读入StringReader,将其包装在InputSource中,然后将其传递给DocumentBuilder:
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new InputSource(new StringReader(xml)));发布于 2010-06-16 08:43:47
假设XML是一个字符串,不要被接受字符串的版本搞混了--字符串是一个URL,而不是您的输入!
您需要的是接受输入流的版本。
您需要基于字符串创建一个输入流(我将尝试查找代码示例,但您可以在Google上搜索)。通常会涉及到StringReader。
https://stackoverflow.com/questions/3050036
复制相似问题