Eviware Forum

soapUI => soapUI => Topic started by: R. Wiertz on May 09, 2007, 12:54:07 pm



Title: GroovyScript: Getting node value out XML
Post by: R. Wiertz on May 09, 2007, 12:54:07 pm
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:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <soap:Body>
      <ValideerBerichtResponse xmlns="urn:mijntestsite">
         <EIValidatieWrapper>
            <EIValidatieBericht>
               <Foutmeldingen xmlns="">
                  <Structureel/>
                  <Inhoudelijk/>
                  <Bedrijfsregels>
                     <Foutmelding>
                        <Code>9003</Code>
                        <Omschrijving>Bericht voldoet niet aan AZR-bedrijfsregel 3</Omschrijving>
                        <Regel>
                           <Regelnummer>3</Regelnummer>
                           <Start>1</Start>
                           <Lengte>250</Lengte>
                           <Bron>3</Bron>
                        </Regel>
                     </Foutmelding>
                  </Bedrijfsregels>
               </Foutmeldingen>
            </EIValidatieBericht>
         </EIValidatieWrapper>
      </ValideerBerichtResponse>
   </soap:Body>
</soap:Envelope>


I want to getall  the values between the node : <Bedrijfsregels>
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?????


Title: Re: GroovyScript: Getting node value out XML
Post by: omatzura on May 09, 2007, 01:53:13 pm
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

 <Foutmeldingen xmlns="">

element you should not include any namespace prefix

regards!

/Ole
eviware.com



Title: Re: GroovyScript: Getting node value out XML
Post by: R. Wiertz on May 09, 2007, 01:59:52 pm
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!


Title: Re: GroovyScript: Getting node value out XML
Post by: omatzura on May 09, 2007, 03:17:34 pm
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


Title: Re: GroovyScript: Getting node value out XML
Post by: R. Wiertz on May 11, 2007, 11:57:52 am
Tanxs that's just what i wanted.