cancel
Showing results for 
Search instead for 
Did you mean: 

xpath and getNodeValues

Occasional Contributor

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

Re: xpath and getNodeValues

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
Occasional Contributor

Re: xpath and getNodeValues

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

Re: xpath and getNodeValues

Ok!

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

regards,

/Ole
eviware.com
Occasional Contributor

Re: xpath and getNodeValues

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
New Here?
Join us and watch the welcome video:
Announcements