x <- read_xml("")
xml_attr(x, "id")
xml_attr(x, "apple")
xml_attrs(x)
kids <- xml_children(x)
kids
xml_attr(kids, "id")
xml_has_attr(kids, "id")
xml_attrs(kids)
# Missing attributes give missing values
xml_attr(xml_children(x), "d")
xml_has_attr(xml_children(x), "d")
# If the document has a namespace, use the ns argument and
# qualified attribute names
x <- read_xml('
')
doc <- xml_children(x)[[1]]
ns <- xml_ns(x)
xml_attrs(doc)
xml_attrs(doc, ns)
# If you don't supply a ns spec, you get the first matching attribute
xml_attr(doc, "id")
xml_attr(doc, "b:id", ns)
xml_attr(doc, "id", ns)
# Can set a single attribute with `xml_attr() <-` or `xml_set_attr()`
xml_attr(doc, "id") <- "one"
xml_set_attr(doc, "id", "two")
# Or set multiple attributes with `xml_attrs()` or `xml_set_attrs()`
xml_attrs(doc) <- c("b:id" = "one", "f:id" = "two", "id" = "three")
xml_set_attrs(doc, c("b:id" = "one", "f:id" = "two", "id" = "three"))
Run the code above in your browser using DataLab