为什么会出现此错误:removeNode目前仅适用于内部节点(Why this error: removeNode only works on internal nodes at present)

编程入门 行业动态 更新时间:2024-10-15 02:31:33
为什么会出现此错误:removeNode目前仅适用于内部节点(Why this error: removeNode only works on internal nodes at present)

我正在编写一个相当简单的R脚本,它将生成一些XML。 我正在使用XML包并执行以下操作:

doc <- newXMLDoc() root = newXMLNode("Root", namespaceDefinitions=c("xsi"="http://www.w3.org/2001/XMLSchema-instance"), doc=doc) newXMLNode("Foo", sample(g_IDS, 1), parent=root) #g_IDS is a vector with some random guids

然后很多:

bar = newXMLNode("bar", parent = root)

添加了更多节点,bar也获得了一些子节点。 有很多对newXMLNode的调用,我没有删除任何节点(至少不是故意的)。

最后,我将所有内容写入如下文件:

cat(saveXML(doc, file = "out.xml"))

这有效,但我收到50条警告说:

在removeNodes.list(kids)中:removeNode目前仅适用于内部节点

我无法为我的生活找出原因。 有人知道吗?

I am writing a fairly simple R script that will generate some XML. I am using the XML package and doing something like this:

doc <- newXMLDoc() root = newXMLNode("Root", namespaceDefinitions=c("xsi"="http://www.w3.org/2001/XMLSchema-instance"), doc=doc) newXMLNode("Foo", sample(g_IDS, 1), parent=root) #g_IDS is a vector with some random guids

And then a lot of:

bar = newXMLNode("bar", parent = root)

More nodes are added and bar gets some child nodes as well. There are a lot of calls to newXMLNode and I am not removing any nodes (at least not knowingly).

At the end I write everything to a file like this:

cat(saveXML(doc, file = "out.xml"))

This works, but I get 50 warnings that say:

In removeNodes.list(kids) : removeNode only works on internal nodes at present

and I cannot for the life of me figure out why. Does anyone know?

最满意答案

最近遇到这种情况,修复来自正确下标列表的任何命名元素。 可能g_IDS维护其元素的名称,因此考虑获取返回的sample()第一个元素: newXMLNode("Foo", sample(g_IDS, 1)[[1]], parent=root)

展示:

g_IDs <- setNames(as.list(seq(1,50,1)), paste0("ID", seq(1,50,1))) # $ID1 # [1] 1 # $ID2 # [1] 2 # $ID3 # [1] 3 ... doc <- newXMLDoc() root = newXMLNode("Root", namespaceDefinitions=c("xsi"="http://www.w3.org/2001/XMLSchema-instance"), doc=doc) newXMLNode("Foo", sample(g_IDs, 1), parent=root) # <Foo>1</Foo> # Warning message: # In removeNodes.list(kids) : # removeNode only works on internal nodes at present doc <- newXMLDoc() root = newXMLNode("Root", namespaceDefinitions=c("xsi"="http://www.w3.org/2001/XMLSchema-instance"), doc=doc) newXMLNode("Foo", sample(g_IDs, 1)[[1]], parent=root) # <Foo>4</Foo>

Recently running into this situation, the fix came with properly subscripting any named elements of list. Possibly g_IDS maintains names to its elements, so consider taking first element of the returned sample(): newXMLNode("Foo", sample(g_IDS, 1)[[1]], parent=root)

To demonstrate:

g_IDs <- setNames(as.list(seq(1,50,1)), paste0("ID", seq(1,50,1))) # $ID1 # [1] 1 # $ID2 # [1] 2 # $ID3 # [1] 3 ... doc <- newXMLDoc() root = newXMLNode("Root", namespaceDefinitions=c("xsi"="http://www.w3.org/2001/XMLSchema-instance"), doc=doc) newXMLNode("Foo", sample(g_IDs, 1), parent=root) # <Foo>1</Foo> # Warning message: # In removeNodes.list(kids) : # removeNode only works on internal nodes at present doc <- newXMLDoc() root = newXMLNode("Root", namespaceDefinitions=c("xsi"="http://www.w3.org/2001/XMLSchema-instance"), doc=doc) newXMLNode("Foo", sample(g_IDs, 1)[[1]], parent=root) # <Foo>4</Foo>

更多推荐

本文发布于:2023-08-06 18:50:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1454496.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:适用于   节点   错误   removeNode   error

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!