r-lib / xml2

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

xml2 is not removing namespaced attributes #387

Open cole-johanson opened 1 year ago

cole-johanson commented 1 year ago

Possibly related to 340.

The xml2 Node Modification vignette states that using NULL as the value will remove the attribute completely. In the example below, the 'space' attribute in doc1 is correctly removed using this method. However, the 'xml:space' attribute in doc2 is not getting removed using this method.

library(xml2)
doc1 = as_xml_document('<xml><t space="preserve">1</t><t space="preserve">2</t></xml>')
doc1_children = xml_children(doc1)
xml_attrs(doc1_children) <- NULL
print(doc1_children)
#> {xml_nodeset (2)}
#> [1] <t>1</t>
#> [2] <t>2</t>

doc2 = as_xml_document('<xml><t xml:space="preserve">1</t><t xml:space="preserve">2</t></xml>')
doc2_children = xml_children(doc2)
xml_attrs(doc2_children) <- NULL
print(doc2_children)
#> {xml_nodeset (2)}
#> [1] <t xml:space="preserve">1</t>
#> [2] <t xml:space="preserve">2</t>

Created on 2023-04-24 with reprex v2.0.2