我在变量doc中有一个XML文档。例如,xml_attr(doc, "attr")从其属性attr="200"中打印出值200。
xml_set_attr(doc, "attr", "")确实删除了该值,但我希望从标记中删除attr属性,以便文档看起来如下:
<tag></tag>而不是
<tag attr></tag>或
<tag attr=""></tag>
xml2有此功能吗?
发布于 2018-08-19 14:42:58
尝试分配NULL以删除该属性:
library(xml2)
(doc <- read_xml("<tag value='200'></tag>"))
# {xml_document}
# <tag value="200">
xml_set_attr(doc, "value", NULL)
doc
# {xml_document}
# <tag>https://stackoverflow.com/questions/51918672
复制相似问题