字符串作为文档
我正在遵循有关使用 XPath 解析 XML 的教程,它给出了打开文档的以下示例:
DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
domFactory.setNamespaceAware(true); // never forget this!
DocumentBuilder builder = domFactory.newDocumentBuilder();
Document doc = builder.parse("books.xml");
我想做的是更改它,以便 Document
正在读取 我已经创建的 String
变量,而不是从文件中读取。我怎样才能做到这一点?
I'm following this turorial on parsing XML with XPath, and it gives the following example to open a document:
DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
domFactory.setNamespaceAware(true); // never forget this!
DocumentBuilder builder = domFactory.newDocumentBuilder();
Document doc = builder.parse("books.xml");
What I would like to do, is change that so that the Document
is reading a String
variable that I already have made, instead of reading from a file. How can I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请查看此处
Look here
你可以试试这个:
You may try this one: