Forum Discussion

R__Wiertz's avatar
R__Wiertz
Occasional Contributor
18 years ago

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?????
  • omatzura's avatar
    omatzura
    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

  • R__Wiertz's avatar
    R__Wiertz
    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!
  • omatzura's avatar
    omatzura
    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