[R] adding a node in an existing xml file

hs hsansegundo at meteo.cat
Thu Aug 6 13:59:14 CEST 2015


I have an xml file like this:
<?xml version="1.0" encoding="utf-8" ?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document id="root_doc">
<Schema name="sql_statement" id="sql_statement">
	<SimpleField name="Name" type="string"></SimpleField>
	<SimpleField name="Description" type="string"></SimpleField>
</Schema>

<Folder>
  <name>sql_statement</name>
  <Placemark>
	<name>2013/11/16 00:02:16</name>
	<description>2013/11/16 00:02:16</description>
	<ExtendedData><SchemaData schemaUrl="#sql_statement">
		<SimpleData name="value1l">70.3</SimpleData>
		<SimpleData name="value2">65562</SimpleData>
	</SchemaData></ExtendedData>
     
<Point><coordinates>3.611564270451177,39.118047789677419</coordinates></Point>
  </Placemark>
 
</Folder>
</Document>
</kml>


I'm able to read the xml file with the xml package and navigate into the tag
values.

d = xmlParse("testkml.kml")
xmlfile<-d
xmltop = xmlRoot(xmlfile) #gives content of root
vxmlName<-xmlName(xmltop) #give name of nodt
vxmlNametop1<-xmlName(xmltop[[1]])         #<Document>
vxmlNametop11<-xmlName(xmltop[[1]][[1]]) #<Schema>
vxmlNametop12<-xmlName(xmltop[[1]][[2]]) #<Folder>


I need to create childs (

<Folder>
  <name>sql_statement</name>
  <Placemark>
	<name>2013/11/16 00:02:16</name>
	<description>2013/11/16 00:02:16</description>
	<ExtendedData><SchemaData schemaUrl="#sql_statement">
		<SimpleData name="value1l">70.3</SimpleData>
		<SimpleData name="value2">65562</SimpleData>
	</SchemaData></ExtendedData>
     
<Point><coordinates>3.611564270451177,39.118047789677419</coordinates></Point>
  </Placemark>
 
</Folder>
</Document>
</kml>

somebody can help me how to do it?
Thanks



--
View this message in context: http://r.789695.n4.nabble.com/adding-a-node-in-an-existing-xml-file-tp4710824.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list