getNodeValue return null if I add ns

Anonymous
Not applicable
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2019
05:10 AM
06-08-2019
05:10 AM
getNodeValue return null if I add ns
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <CheckCity xmlns="http://some ns here"> <Result> <table> <country>CountryA</country> <city>CityA</city> </table> <table> <country>CountryB</country> <city>cityB</city> </table> <table> <country>CountryC</country> <city>cityC</city> </table> </Result> </CheckCity> </soap:Body> </soap:Envelope>
I need to check that CountyA has city A, CountryB has city B, CountryC hs City C
I can't city value for the country. getNOdeValue returns null
def groovyUtils=new com.eviware.soapui.support.GroovyUtils(context) def holder=groovyUtils.getXmlHolder("SOAP#Response") def soap = new groovy.xml.Namespace("http://schemas.xmlsoap.org/soap/envelope/", 'soap') holder.namespaces["ns"] = "http://some ns here" def a = holder.getNodeValue("//ns:table[country='CountryA']//*:city") log.info a
If I remove ns from xml and use smth like def a = holder.getNodeValue("//*:table[country='CountryA']//*:city") works ok
3 REPLIES 3
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2019
03:20 AM
06-10-2019
03:20 AM
Namespace is not added in your response. And also, getNodeValue() gets the exact xpath of the response.
So, for this particular line to be executed properly:-
def a = holder.getNodeValue("//ns:table[country='CountryA']//*:city")
Your response should look like this:-
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <CheckCity xmlns="http://some ns here"> <Result> <ns:table> <country>CountryA</country> <city>CityA</city> <ns:/table> <ns:table> <country>CountryB</country> <city>cityB</city> <ns:/table> <ns:table> <country>CountryC</country> <city>cityC</city> <ns:/table> </Result> </CheckCity> </soap:Body> </soap:Envelope>
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2019
02:54 AM
06-11-2019
02:54 AM
The question is still actual. How can I get a city for CountryA?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2019
03:01 AM
06-11-2019
03:01 AM
May be understanding namespaces might help you
https://www.oracle.com/technetwork/articles/srivastava-namespaces-092580.html
Regards,
Rao.
https://www.oracle.com/technetwork/articles/srivastava-namespaces-092580.html
Regards,
Rao.
