cancel
Showing results for 
Search instead for 
Did you mean: 

GroovyScript: Getting node value out XML

Highlighted
Occasional Contributor

GroovyScript: Getting node value out XML

Hello,

Can somebody tell me how i can get a node value out of XML.
I want to do that with a groovy script because i have to compaire the values.

My xml message is:


   
     
         
           
               
                 
                 
                 
                     
                        9003
                        Bericht voldoet niet aan AZR-bedrijfsregel 3
                       
                           3
                           1
                           250
                           3
                       

                     

                 

               

           

         

     

   



I want to getall  the values between the node :
I use the code below, but that didn't work.

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
log.info( groovyUtils.projectPath )

//create holder for last response an log requistID
def holder = groovyUtils.getXmlHolder( "EI-Bericht#response" )
def strlItems = holder.getNodeValues( "//ns1:Bedrijfsregels")
log.info( strlItems["Omschrijving"] )



What do i wrong?????
4 REPLIES 4
Highlighted
Super Contributor

Hi!

the results returned by getNodeValues is just a list of strings, not a Map.. try to use

log.info( holder.getNodeValue( "//Omschrijving") )

instead.. due to the
element you should not include any namespace prefix

regards!

/Ole
eviware.com

Highlighted
Occasional Contributor

Thank you.

But can you also tel me how to work wit the property : GetNodeValues.
Because i try to get that work but i don't get it.
I tried several declarations but i don't get it!
Highlighted
Super Contributor

Hi!

getNodeValues returns a string array of node values, so you need to specify an xpath expression that selects multiple nodes.. for your document you could try

def items = holder.getNodeValues( "//Foutmelding/descendant::*")
for (item in items) { log.info( item ) }

which will dump the contents of all descendants to Foutmelding

regards,

/Ole
eviware.com
Highlighted
Occasional Contributor

Tanxs that's just what i wanted.
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors