fileName <- system.file("exampleData", "mtcars.xml", package="XML")
doc <- xmlTreeParse(fileName)
xmlAttrs(xmlRoot(doc))
xmlAttrs(xmlRoot(doc)[["variables"]])
doc <- xmlParse(fileName)
d = xmlRoot(doc)
xmlAttrs(d)
xmlAttrs(d) <- c(name = "Motor Trend fuel consumption data",
author = "Motor Trends")
xmlAttrs(d)
# clear all the attributes and then set new ones.
removeAttributes(d)
xmlAttrs(d) <- c(name = "Motor Trend fuel consumption data",
author = "Motor Trends")
# Show how to get the attributes with and without the prefix and
# with and without the URLs for the namespaces.
doc = xmlParse('
')
xmlAttrs(xmlRoot(doc)[[1]], TRUE, TRUE)
xmlAttrs(xmlRoot(doc)[[1]], FALSE, TRUE)
xmlAttrs(xmlRoot(doc)[[1]], TRUE, FALSE)
xmlAttrs(xmlRoot(doc)[[1]], FALSE, FALSE)
Run the code above in your browser using DataLab