我有XML文件,包含37个主要文件夹,每个主要文件夹包含次要文件夹数量,每个次要文件夹包含3个地点标记。将节点插入XML文件中的某个节点使用R
我想将此节点添加到第一个主要文件夹中的第一个次要文件夹的第一个地标。
我想这样做,但有些问题面临我... 第一有我的节点,我想补充
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)
这里就是我想...
data <- xmlTreeParse("xml_data.xml")
data$doc$children$Folder[[4]][[3]][[3]]$description <- top
saveXML(data, file ="xml_data.xml")
第一个问题是:当我在控制台中写入“data$doc$children$Folder[[4]][[3]][[3]]
”时,说明节点不会出现在控制台中,当我写入“data$doc$children$Folder[[4]][[3]][[3]]$description
”时,它就会出现,我不知道为什么会发生这种情况。
第二个问题是:当我使用saveXML
检查是否说明是在第一个地点标记或不....出现这个错误..
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘saveXML’ for signature ‘"XMLDocument"’
我搜索了这一点,我发现我应该使用data <- xmlTreeParse(Url,useInternalNodes = TRUE)
。 ...但这不允许我使用data$doc$children$Folder[[4]][[3]][[3]]
...
所以请问,有没有办法将节点添加到xml文件中的这个位置?还是有解决我的问题?
here's我的xml文件。
您似乎想要将HTML表格嵌入到XML文件中。你可以建议在XML文件中使用编号索引而不是元素名称path -' [[4]] [[3]] [[3]]'不容易看到吗? – Parfait
我使用'[[4]] [[3]] [[3]]'....我使用这个公式,因为当我在'data $ doc $ children $ Folder'后使用$时,我只有3个选项,是其他36选项,所以第4号指示第一个主文件夹,[[3]]指示第一个次要文件夹和[[3]]指示第一个地标 –
@Parfait,我发现一种方法来添加html到XML,但仍然存在的问题,我不能将XML保存到我的电脑上的文件,请告诉我,如果你知道吗? 'data $ doc $ children $ Folder [[4]] [[3]] [[3]] [[“description”]] < - top' –