gpt4 book ai didi

java - 将节点添加到 org.w3c.dom.NodeList

转载 作者:太空宇宙 更新时间:2023-11-04 13:09:21 25 4
gpt4 key购买 nike

如何添加节点

Element node = (Element) xpath.evaluate("//property[@value = 'entryDataTitle']", doc, XPathConstants.NODE);

到我的 org.w3c.dom.NodeList?

NodeList entryDataItem = (NodeList) xpath.evaluate("//item[@name='entryDataItem']", doc, XPathConstants.NODESET);

最佳答案

(我假设这些节点/元素都具有相同的父文档,如果不让我知道的话。)我将获取该 NodeList (entryDataItem) 的父节点并使用 appendChild:

parentOfEntryDataItem.appendChild(node);

您可能必须将节点转换为节点,而不是元素。如果您稍后需要该 NodeList,您可以直接说:

NodeList x = entryDataItem.getChildNodes();

关于java - 将节点添加到 org.w3c.dom.NodeList,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34134856/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com