如何从现有的构建器节点构建新的文档构建器?
我有以下代码:
DocumentBuilderFactory dbFactory_ = DocumentBuilderFactory.newInstance();
Document doc_;
DocumentBuilder dBuilder = dbFactory_.newDocumentBuilder();
StringReader reader = new StringReader(s);
InputSource inputSource = new InputSource(reader);
doc_ = dBuilder.parse(inputSource);
doc_.getDocumentElement().normalize();
然后遍历 doc_ 以获取特定节点。然后我想用该节点创建一个新的 dBuilder。到目前为止,我一直在尝试将节点转换为字符串,然后使用 dBuilder.parse 字符串,但收效甚微,但这并没有起作用,因为我遇到了命名空间问题,并且其他事情。
<Random>
<Fixed></Fixed>
</Random>
因此,我将取出
节点并创建一个全新的类,其中它是根节点。
I have the following code:
DocumentBuilderFactory dbFactory_ = DocumentBuilderFactory.newInstance();
Document doc_;
DocumentBuilder dBuilder = dbFactory_.newDocumentBuilder();
StringReader reader = new StringReader(s);
InputSource inputSource = new InputSource(reader);
doc_ = dBuilder.parse(inputSource);
doc_.getDocumentElement().normalize();
and then I traverse doc_
in order to get a specific node. I would then like to create a new dBuilder with that node. What I've been trying so far with little success is to convert my node to a string and then have the dBuilder.parse
the string but that has not been working because I'm running into namespace problems and other things.
<Random>
<Fixed></Fixed>
</Random>
So with this I would take the <Fixed>
node out and create a completely new class where it is the root node.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建一个新文档,然后将您的节点导入其中,如下所示:
Create a new document and then import your node into it, as shown below: