我从Google地球专业版导出的kml文件,由37个文件夹组成,每个文件夹包含" minor"文件夹,总数"次要"文件夹是168,每个"次要"有3个地标。
我是HTML代码,我使用R制作,并希望将此kml文件导入R并将此HTML代码放入第一个"地标"对于每个"未成年人"文件夹,这个HTML代码不是常量,它有像这个代码中表格中的值一样的变量,这个变量将附加在我为这个" minor"文件夹,当我编辑这个HTML代码时,我会将它放入第一个"地标"对于这个"未成年人"文件夹,等等其他"未成年人"文件夹。
R中是否有任何功能可以将此html代码添加到kml文件中?
这里是"描述"的代码。在R.
URL <- paste("file:///C:/Users/pc/Downloads/Googletraffic/Tazbet/Autostrad;Helwan To Da2ery/",FileName,sep = "")
library(XML)
top = newXMLNode("description")
table = newXMLNode("table ", attrs = c(width = 300, border = 1), parent = top)
tbody <- newXMLNode("tbody",parent = tr)
tr <- newXMLNode("tr",parent = table)
th <- newXMLNode("th",attrs = c(scope = "col"),scope1 = max(Bey2ollak$V3),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 = table)
th <- newXMLNode("th",attrs = c(scope = "col"),scope1 = max(Bey2ollak$V3),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 = table)
th <- newXMLNode("th",attrs = c(scope = "col"),scope1 = max(Bey2ollak$V3),parent = tr)
th <- newXMLNode("th",attrs = c(scope = "col"),scope1 = "MD",parent = tr)
th <- newXMLNode("th",attrs = c(scope = "col"),scope1 = "PM",parent = tr)
th <- newXMLNode("img",attrs = c(src = URL,width = "700",height= "777",alt=""),parent =top )
top
这是控制台中的输出
<description>
<table width="300" border="1">
<tr>
<th scope="col">5</th>
<th scope="col">MD</th>
<th scope="col">PM</th>
</tr>
<tr>
<th scope="col">5</th>
<th scope="col">MD</th>
<th scope="col">PM</th>
</tr>
<tr>
<th scope="col">5</th>
<th scope="col">MD</th>
<th scope="col">PM</th>
</tr>
</table >
<img src="file:///C:/Users/pc/Downloads/Googletraffic/Tazbet/Autostrad;Helwan To Da2ery/Spiral.jpg " width="700" height="777" alt=""/>
</description>
here's我的kml文件
答案 0 :(得分:1)
我发现但效率不高,我在NotePad ++上打开kml文件,然后获取root并将其放入xml文件中,然后使用此代码读取xml,
Url <- "xml_data1.xml"
data <- xmlTreeParse(Url)
xmlTreeParse()
允许我将xml文件解析为列表,所以我可以将任何东西添加到xml文件中的特定位置,这就是我用来添加节点的代码
data$doc$children$Folder[[3]][[3]][[3]][["description"]] <- top
请注意XMLInternalElementNode
和XMLNode
之间存在差异,因此您无法像这样直接使用saveXML()
..
saveXML(data, file ="xml_data2.kml")
你应该首先获得数据根
xmlroot <- xmlRoot(data)
saveXML(xmlroot, file ="xml_data2.xml")
写这个xml的答案是here
然后您可以使用NotePad ++打开xml_data2.xml并获得您想要的内容,然后将其重新放入kml文件中。