I've XML file, consist of 37 Major folder,each major folder has number of minor folders, and each minor folder has 3 placemarks.
i wanna add this node to the first placemark at this first minor folder which in the first major folder.
i tried to do that, but some problems faced me ... first there's my node which i wanna add
top = newXMLNode("description")
table = newXMLNode("table", attrs = c(width = 300, border = 1), parent = top)
tbody <- newXMLNode("tbody",parent = table)
tr <- newXMLNode("tr",parent = tbody)
th <- newXMLNode("th",attrs = c(scope = "col"),scope1 = 5,parent = tr)
th <- newXMLNode("th",attrs = c(scope = "col"),scope1 = "MD",parent = tr)
th <- newXMLNode("th",attrs = c(scope = "col"),scope1 = "PM",parent = tr)
tr <- newXMLNode("tr",parent = tbody)
th <- newXMLNode("th",attrs = c(scope = "col"),scope1 = 5,parent = tr)
th <- newXMLNode("th",attrs = c(scope = "col"),scope1 = "MD",parent = tr)
th <- newXMLNode("th",attrs = c(scope = "col"),scope1 = "PM",parent = tr)
tr <- newXMLNode("tr",parent = tbody)
th <- newXMLNode("th",attrs = c(scope = "col"),scope1 =5,parent = tr)
th <- newXMLNode("th",attrs = c(scope = "col"),scope1 = "MD",parent = tr)
th <- newXMLNode("th",attrs = c(scope = "col"),scope1 = "PM",parent = tr)
tbody <- newXMLNode("tbody",parent = table)
th <- newXMLNode("img",attrs = c(src = URL,width = "700",height= "777",alt=""),parent =top )
here's what i tried ...
data <- xmlTreeParse("xml_data.xml")
data$doc$children$Folder[[4]][[3]][[3]]$description <- top
saveXML(data, file ="xml_data.xml")
first problem is : when i write "data$doc$children$Folder[[4]][[3]][[3]]" in console, the description node doesn't appear in the the console and when i write "data$doc$children$Folder[[4]][[3]][[3]]$description" it appears and i don't know why this happens..
2nd problem is : when i use saveXMLto check if description is in the first place mark or not .... this error appears..
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘saveXML’ for signature ‘"XMLDocument"’
i searched for this and i found i should use data <- xmlTreeParse(Url,useInternalNodes = TRUE ) .... but this doesn't allow me to use data$doc$children$Folder[[4]][[3]][[3]]...
so please, is there a way to add the node to this position in the xml file ? or is there a solution for my problems ?
here's my xml file .
[[4]][[3]][[3]]is not easily seen?data$doc$children$Folder[[4]][[3]][[3]][["description"]] <- top