xml2 icon indicating copy to clipboard operation
xml2 copied to clipboard

xml2 is not removing namespaced attributes

Open cole-johanson opened this issue 1 year ago • 0 comments

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

cole-johanson avatar Apr 24 '23 15:04 cole-johanson