Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在变量中有一个 XML 文档doc。xml_attr(doc, "attr")例如200从其属性中打印出值attr="200"。
doc
xml_attr(doc, "attr")
200
attr="200"
xml_set_attr(doc, "attr", "")确实删除了该值,但我想attr从标签中删除该属性,因此文档如下所示:
xml_set_attr(doc, "attr", "")
attr
<tag></tag>代替
<tag></tag>
<tag attr></tag>或者
<tag attr></tag>
<tag attr=""></tag>
xml2 有这个功能吗?
尝试分配NULL以删除属性:
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>