Forum Discussion

ThomasAu's avatar
ThomasAu
Contributor
15 years ago

Help grabbing contents of a specific node

Hello.

in the following example, I would like to grab the guid of "ABC". can somebody tell me how to do it?


<node1>
<node2>
<guid>11.0</guid>
<name>ABC</name>
<description>ABCdescription</description>
</node2>
<node2>
<guid>12.0</guid>
<name>DEF</name>
<description>DEFdescription</description>
</node2>
</node1>


the following does not work:


//node1/node2[@name="ABC"]/guid

//node1/node2/[@name="ABC"]/guid

//node1/node2/name[@name="ABC"]/guid



Can anyone tell me what I am doing wrong?

Thanks.

17 Replies

  • deepesh.jain wrote:
    You don't need the property transfer step. You only need directly a properties step or directly soap step.

    You can use groovy step to populate the xml tag in soap step or property in properties step.

    This is how you can do it assuming your second SOAP step is named as SOAP_2:

    // say in your groovy step you have guid stored in [b]sourceGuid[/b].
    def gUtils = new com.eviware.soapui.support.GroovyUtils( context );
    def holder = gUtils.getXmlHolder("SOAP_2#Request");
    holder.setNodeValue("YOUR_XPATH_HERE",sourceGuid);
    holder.updateProperty();


    Regards,
    Deepesh Jain



    Or, in your old example, can I put the guid directly into my properties file using groovy?


    for (i in 1..Integer.parseInt(totalcount))
    {
    def name1 = holder.getNodeValue("//node1/node2[i]/name") ;
    def guid1 = holder.getNodeValue("//node1/node2[i]/guid") ;
    if (name1 == "ABC")
    {
    //insert value of guid1 into #property_file#${guid} (i don't know the syntax, can you help me?)
    }
    }

  • klitchev's avatar
    klitchev
    Occasional Contributor
    You can do the following:

    //node2/name[text()="ABC"]/../guid


    Just put this in the XPath box for the Source of the property transfer. And don't forget to select the Source step and Property: Response
  • klitchev wrote:
    You can do the following:

    //node2/name[text()="ABC"]/../guid


    Just put this in the XPath box for the Source of the property transfer. And don't forget to select the Source step and Property: Response



    Wow, thank you so much. It was the "/../" that did it.

    Deepesh, thanks a lot for your help too. I learned a lot about groovy thanks to you. However, this was originally what I was looking for.
  • klitchev wrote:
    You can do the following:

    //node2/name[text()="ABC"]/../guid


    Just put this in the XPath box for the Source of the property transfer. And don't forget to select the Source step and Property: Response



    Hi Klitchev,

    Can you tell me if it's possible to do this while using the following to ignore namespaces?

    The XML changed and now I have a //Response namespace so I'm trying to ignore it by using:

    //*[local-name()='node2']/*[local-name()='name'][text()="ABC"]/../*[local-name()='guid']


    So far that is not working and it may be do to syntax? I'm not sure.


    Thanks
  • This is not working either:



    //*[local-name()='node2']/*[local-name()='name' and text()="ABC"]/../*[local-name()='guid']
  • The previous solution worked.

    My problem was that the response that came back was a conversion from JSON.

    So I realized i did not change "Response" drop down to "ResponseAsXML".