XML is very useful format for the purpose of data transfer. In here we are going to deal with two packages for xml manipulation; XML and xml2.
In case of xml2 library, first we have to import library itself.
library("xml2")
then in order to read content of file with path a into xml structure, we have to use function read_xml
xml <- read_xml(a)
now, in order to get list of all xml children, use function xml_children like in case:
x <- xml_children(xml)
If you want to access elements of particular child from your xml structure, do it in this way
first <- xml_children(xml[1])
Finally with function of xml_text, you have to provide argument of xml child you want to get value from.
text <- xml_text(first[1])
And if attribute of that child is about, this is the way.
attr <- xml_attr(x[1], b)
Where b is path to file with xml content.
And there is second interesting library and that is xml
library("xml")
xml <- xmlToDataFrame(a)
where a is path to file with xml content.
For video tutorial, check link below.
No comments:
Post a Comment