Forum Discussion

Serg1981's avatar
Serg1981
Occasional Contributor
13 years ago

Assert kml elements in soapUI

I have kml response, so is it possible to assert elements with XPath assertions?
I know that element can be found with contain/not contain assertions, but I'd like to find elements with something like XPath (IMHO: this assertion type is the best for xml based responses). Is there a way to convert kml response to xml to use XPath assertions?

For example, I need to check coordinates within the response:
<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>


I cannot find element <coordinates>5, 2</coordinates> with XPath: "//kml/Document/Placemark/ComponentString[1]/coordinates"
Any suggestions?
Thanks in advance.

1 Reply

  • 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.