r-lib / xml2

Bindings to libxml2
https://xml2.r-lib.org/
Other
218 stars 83 forks source link

Implement `c.xml_nodeset` #433

Open AshesITR opened 9 months ago

AshesITR commented 9 months ago

Since c.xml_nodeset ist not defined, combining nodesets drops the class and breaks the following usage if not manually applying the class:

library(xml2)
xml <- xml_ns_strip(read_xml(xml2_example("order-doc.xml")))
st <- xml_find_all(xml, "//shipTo")
bt <- xml_find_all(xml, "//billTo")
both <- c(st, bt)
class(both) <- "xml_nodeset"
xml_find_all(both, "name")
#> {xml_nodeset (2)}
#> [1] <name>Alice Smith</name>
#> [2] <name>Robert Smith</name>

xml_find_all(c(st, bt), "name")
#> Error in UseMethod("xml_find_all"): no applicable method for 'xml_find_all' applied to an object of class "list"

Created on 2023-12-13 with reprex v2.0.2