never tried XPath, how about XmlParser?
map = [
"Name1" : "5, 2",
"Name2" : "6, 89"
]
def file =
"""
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:ns2="http://www.w3.org/2005/Atom" xmlns:ns3="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0">
<Document>
<name>System Layer</name>
<Placemark>
<name>Name1</name>
<ComponentString>
<coordinates>5, 2</coordinates>
</ComponentString>
</Placemark>
<Placemark>
<name>Name2</name>
<ComponentString>
<coordinates>6, 8</coordinates>
</ComponentString>
</Placemark>
</Document>
</kml>
"""
xml = new XmlParser().parseText(file);
xml.Document.Placemark.each {
assert it.ComponentString.coordinates.text() == map[it.name.text()]
}
This will, intentionally, throw an error for the second set of coordinates.