vb.net - iterate through every xml node and append node and value to string -
i have following xml format,which kml file google map..
<kml xmlns="http://www.opengis.net/kml/2.2"> <document> <name>testdoc</name> <style id="style1"> <polystyle> <fill>0</fill> </polystyle> </style> <folder> <name>folder1</name> <placemark> <name>placemark1folder1</name> <lookat> <longitude>-122.0839597145766</longitude> <latitude>37.42222904525232</latitude> </lookat> </placemark> <placemark> <name>placemark2folder1</name> <lookat> <longitude>-101.083959</longitude> <latitude>26.422</latitude> </lookat> </placemark> </folder> <folder> <name>folder2</name> <placemark> <name>placemark1folder2</name> <lookat> <longitude>-96.566556</longitude> <latitude>14.422</latitude> </lookat> </placemark> </folder> </document> </kml>
i want concat xml string variable untill finds <folder>
node
hence output string :
""<kml xmlns="http://www.opengis.net/kml/2.2"><document><name>testdoc</name><style id="style1"><polystyle><fill>0</fill></polystyle> </style>"
i new xml ..plz help
ok got ...here solution
public sub concatxmltostring() dim xmldoc xmldocument = new xmldocument() '================================ 'hard coded '================================ dim concatstring string = "<?xml version=" & chr(34) & "1.0" & chr(34) & "encoding=" & chr(34) & "utf-8" & chr(34) & "?><kml xmlns=" & chr(34) & "http://www.opengis.net/kml/2.2" & chr(34) & ">" xmldoc.load("e:\a01c.kml") dim documentnodelist xmlnodelist = xmldoc.getelementsbytagname("document") each documentnode xmlnode in documentnodelist 'xmldoc.parentnode.parentnode.removechild(childnode) dim childnodelist xmlnodelist = documentnode.childnodes each childnode xmlnode in childnodelist if childnode.name <> "folder" concatstring = concatstring & childnode.outerxml.replace("xmlns=""http://www.opengis.net/kml/2.2""", "") end if next next concatstring = concatstring & "</document></kml>" dim str string = xmldoc.innertext end sub
Comments
Post a Comment