editing kml with ps.
-
Wednesday, January 11, 2012 5:38 PM
So I think the problem jrv sighted in my last post (about my xpath having no chance) maybe coming back to bite me. Strange thing is that in that case it worked but here it is not. So without further delay:
This works:
foreach ($member in $shplist) { $basename = $member.basename $candidate = [xml] (get-content .\$basename.xml) $nodecount = $candidate.SelectNodes("FeatureCollection/featureMember").count }
But when I try to execute a similar design on a .kml file (something that by all counts is .xml)
foreach ($kmember in $kmllist) { $kcandidate = [xml] (get-content .\$kmember) $knodelist = $kcandidate.SelectNodes("kml/Document") }
it returns an empty array $knodelist.
I think it must have something to do with the format of the .kml but I will be a monkey's uncle if I can find what the difference is.
The format of the .xml is this:
<?xml version="1.0" encoding="utf-8" ?> <FeatureCollection xmlns:xsi=yada yada yada> <featureMember> <next> </next> </featureMember> </FeatureCollection>
and this is that of the .kml<?xml version="1.0" encoding="utf-8" ?> <kml xmlns=yada yada> <Document> <Folder> <name>next</name> <Placemark> </Placemark> </Folder> </Document> </kml>
Any thoughts?
All Replies
-
Wednesday, January 11, 2012 7:30 PMPerhaps my Xpath doesn't have exactly 'no chance'.. just ... a snowball's chance in powershell? :D
-
Thursday, January 12, 2012 12:58 AM
We
Think that Helena Rubinsein woul dbeproud of you Chewy Mascara. Allure wil contact you in a few days. Keep up the good work.
Note that there is no such animal as a KML file. You just made that up to get attention. You and the Kardashians. Khloe would beproud of you.
KML Kardasjian Makeup Extreme. On sale now at your favorite dive.
jv -
Sunday, February 19, 2012 9:20 PMModerator
Hi Chewie,
Were you able to find a solution for this? Please update us on the status.
Thanks,
Rich Prescott | Infrastructure Architect, Windows Engineer and PowerShell blogger | MCITP, MCTS, MCP
Engineering Efficiency
@Rich_Prescott
Windows System Administration tool
AD User Creation tool -
Sunday, February 19, 2012 11:30 PM
Hi Rich,
I think the very first part of the problem was my unfamiliarity with the xml data type. Specifically however I believe my problem was that I was attempting to operate on a list; that returned from the SelectNodes method instead of on an array which what I wanted.
I ended up cycling through the list and adding the unique values to an empty array $a() I created.
$candidate=[xml] (get-content.\$basename.xml) #load the .xml into memory
$groupnodes=$candidate.SelectNodes("FeatureCollection/featureMember/$basename/GROUP/text()") #get the nodes named "GROUP"
$a=@() #creates empty array
foreach($nodein$groupnodes) {
$nodeval=$node.get_value()#get the values of the "GROUP" nodes and...
$a=$a+$nodeval#...add to array
}
It wasn't long after this that a colleague of mine clued me in about something called an 'arraylist' and 'collections'. I never investigated that too deeply but it sounds like the more apprpriate method for what I was tring to do.
Sorry for leaving the post unresolved.
-CM
- Marked As Answer by Chewie Mascara Sunday, February 19, 2012 11:31 PM

