Search code examples
rxml2

xml2 library remove node: LOGICAL() can only be applied to a 'logical', not a 'list'


I am attempting to remove an element from an html document using xml2 library (1.3.2):

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

This results in:

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

ul seems to be correct, of class xml_node with correct content.

Do I mess up something or does xml2 library have a problem? The documentation is extremely sparse.


Solution

  • xml_remove(ul)
    

    this is according to the manual and seems to work.

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

    ul is gone.