XMLSlurper appendNode 没有看到变化
我在使用 XMLSlurper 更新 XML 文档时遇到问题。大多数事情都有效,但在某些情况下,“查找”找不到我刚刚附加的节点(appendNode)。新节点在处理结束时就在那里,但当我在添加子节点时找不到。
我发现一篇关于 XMLSlurper 的文章说,找到新的 Node 需要再次调用 parseText 和/或 StreaMarkupBuilder(见下文)。真的吗?!这看起来太笨拙了,我想我应该验证一下。
这是一个代码片段。即使节点刚刚添加,“查找”也会得到 NoChildren 。
codeNode.appendNode {
'lab:vendorData'() {}
}
vendorNode = codeNode.children().find { it.name() == "vendorData" }
“appendNode 不会直接修改 slurped 文档。当使用 StreamingMarkupBuilder 写出文档时,编辑会“即时”应用。” http://markmail.org/message/5nmxbhwna7hr5zcq#query:lated%3A5nmxbhwna7hr5zcq+page:1+mid:bkdesettsnfnieno+state:结果
为什么我找不到我的新节点?!
I am having troubles using XMLSlurper to update an XML document. Most things work, but in some situations a "find" doesn't find a Node I just appended (appendNode). The new Node is there at the end of processing, but is not found when I am in the middle of adding children.
I found a post about XMLSlurper that says that finding the new Node requires calling parseText again and/or StreaMarkupBuilder (see below). Really?! That seems so kludgy that I thought I'd verify on SO.
Here is a code snippet. The "find" gets NoChildren even though the Node was just added.
codeNode.appendNode {
'lab:vendorData'() {}
}
vendorNode = codeNode.children().find { it.name() == "vendorData" }
"appendNode doea not modify the slurped document directly. The edit is applied "on the fly" when the document is written out using StreamingMarkupBuilder."
http://markmail.org/message/5nmxbhwna7hr5zcq#query:related%3A5nmxbhwna7hr5zcq+page:1+mid:bkdesettsnfnieno+state:results
Why can't I find my new Node?!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这就是我要做的工作。不优雅,但解决了“更新”问题:
}
This is what I got to work. Is not elegant, but got past "update" problem:
}