Forum Discussion

John_R__Brewste's avatar
John_R__Brewste
Occasional Contributor
16 years ago

xpath and getNodeValues

Greeting,

How would I use getNodeValues if I was to get multiple nodes.

for example:


 
    this is a test
 

 
    Yet another test 



If I use:
def holder = groovyUtils.getXmlHolder( "Book Author Search#Response" )
bartest = holder.getNodeVales ( "//bar" );


I can only update the FIRST bar!  I have multiple "bar" that I need to update.  How can I get to the others?

I read in the docs "If the specified XPath expression returns multiple values when getting a value, a String array is returned instead:"  So, I get a string.  I need the reference to the holder for each bar

or, am I thinking wrong?

JOhn

4 Replies

  • omatzura's avatar
    omatzura
    Super Contributor
    Hi John,

    please try using holder.getDomNodes( xpath ) instead which should return a list of DOM nodes that you can then use for modification..

    makes sense?

    regards!

    /Ole
    eviware.com
  • John_R__Brewste's avatar
    John_R__Brewste
    Occasional Contributor
    YEs,

    I just have to comb thru the API to figure out what to use to update.

    Thanks, let me run with that and see what happens.

    J
  • omatzura's avatar
    omatzura
    Super Contributor
    Ok!

    you can use XmlUtils.setNodeValue( node, "..." ) to set the text content of either an attribute or an element..

    regards,

    /Ole
    eviware.com
  • John_R__Brewste's avatar
    John_R__Brewste
    Occasional Contributor
    Well, that made it slap easy.

    def _xmlUtil =      new com.eviware.soapui.support.xml.XmlUtils();

    ...

    newNode = holder.getDomNodes ( "//aps:Value" );

    for ( i in newNode ) {
          _xmlUtil.setNodeValue(i, "newValue");
    }
    holder.updateProperty()

    It was the XmlUtils that I didn't know about.  Thanks for your help!!

    John