xml2 库删除节点:LOGICAL() 只能应用于“逻辑”,而不是“列表”

问题描述

我正在尝试使用 xml2 库 (1.3.2) 从 html 文档中删除元素:

html <- "<html> <ul> <li>foo</li> </ul> </html>"
x <- read_html(html)
ul <- xml_find_first(x,".//ul")
xml_remove(x,ul)

结果:

Error in xml_remove.xml_node(x,ul) : 
  LOGICAL() can only be applied to a 'logical',not a 'list'

ul 似乎是正确的,属于具有正确内容xml_node 类。

是我搞砸了什么还是 xml2 库有问题?文档极其稀少。

解决方法

xml_remove(ul)

这是根据 manual 并且似乎有效。

> print(x)
{html_document}
<html>
[1] <body></body>

ul 不见了。