【发布时间】:2016-12-27 14:12:06
【问题描述】:
我正在解析一个 XMl 文件并使用其中的内容在 java 中使用 XPath 处理数据设置,可能会出现我们可以得到空标签作为输入的情况。
但是当我尝试使用 setNodeValue 和 setTextContent 方法为空节点对象设置值时,仍然遇到同样的问题。我们是否有任何其他选项来设置 null Node 对象的值。
**//Code Snippet:**
Node title = XPathAPI.selectSingleNode("Input Node", "title/text()");
// *Here if there is no input title tag, then the title variable would be null*
title.setNodeValue("Value to set on the null node");
【问题讨论】:
标签: java xml xpath xml-parsing