Ask a Question

getNodeValue return null if I add ns

Anonymous
Not applicable

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
avidCoder
Super Contributor

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>
Anonymous
Not applicable

The question is still actual. How can I get a city for CountryA? 

nmrao
Community Hero

May be understanding namespaces might help you
https://www.oracle.com/technetwork/articles/srivastava-namespaces-092580.html


Regards,
Rao.
cancel
Showing results for 
Search instead for 
Did you mean: