x <- read_xml("<root id='1'><child id ='a' /><child id='b' d='b'/></root>")
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('
<root xmlns:b="http://bar.com" xmlns:f="http://foo.com">
<doc b:id="b" f:id="f" id="" />
</root>
')
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)
Run the code above in your browser using DataLab