【问题标题】:R & XML2: Remove XML attributesR&XML2:移除 XML 属性
【发布时间】:2018-08-19 14:31:33
【问题描述】:

我在变量 doc 中有一个 XML 文档。例如,xml_attr(doc, "attr") 从其属性 attr="200" 中打印出值 200

xml_set_attr(doc, "attr", "") 确实删除了该值,但我想从标签中删除 attr 属性,以便文档看起来像:

<tag></tag> 而不是

<tag attr></tag>

<tag attr=""></tag>


xml2有这个功能吗?

【问题讨论】:

    标签: r xml2


    【解决方案1】:

    尝试分配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>
    

    【讨论】:

      猜你喜欢
      • 2022-01-06
      • 1970-01-01
      • 2021-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多