我有一个xml文件,其中有许多同名的节点。节点的名称不受我的控制。有没有办法访问同名的每个节点的值,而不仅仅是第一个。
在xml_child()的帮助文件中,它指出您可以使用search参数“指定要返回的子节点的名称。如果有多个子节点具有相同的名称,则将返回第一个子节点。”
不幸的是,我也不总是知道具有相同名称的节点的位置,所以我也不能使用数值作为搜索参数。
例如:
# similar example provided in the xml2 documentation
x <- read_xml("<foo> a <d>e1</d> <d>e2</d> </foo>")
# this gives expected output from the first child node named "d"
xml_child(x, "d") %>% xml_contents()
# this gives me expected output from second child node with name "d"
# but I don't always know the position of this node
xml_child(x, 2) %>% xml_contents()那么有没有办法访问名为"d“的第二个节点的值?
发布于 2019-06-08 03:27:57
https://stackoverflow.com/questions/56500182
复制相似问题