header
header
Main Menu
Home
Eviware Store
Downloads
Products
News
Forum
Eviware Blog
Search
FAQs
Customer Area
Support
Documentation
Tutorials
CookBook
Downloads
Forum
Login Form
Welcome, Guest. Please login or register.
December 05, 2008, 12:03:03 am
Username: Password:
Login with username, password and session length

Forgot your password?
 
GroovyScript: Getting node value out XML
Welcome, Guest. Please login or register.
December 05, 2008, 12:03:03 am
Home Help Search Login Register
News: The Forums are up! Welcome to eviware.

+  Eviware Forum
|-+  soapUI
| |-+  soapUI
| | |-+  GroovyScript: Getting node value out XML
« previous next »
Pages: [1] Print
Author Topic: GroovyScript: Getting node value out XML  (Read 1329 times)
R. Wiertz
Soapui Public
Newbie
*
Posts: 6


« 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?Huh?
« Last Edit: May 09, 2007, 01:27:31 pm by R. Wiertz » Logged
omatzura
Administrator
Hero Member
*****
Posts: 1,506


« Reply #1 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

Logged
R. Wiertz
Soapui Public
Newbie
*
Posts: 6


« Reply #2 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!
Logged
omatzura
Administrator
Hero Member
*****
Posts: 1,506


« Reply #3 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
Logged
R. Wiertz
Soapui Public
Newbie
*
Posts: 6


« Reply #4 on: May 11, 2007, 11:57:52 am »

Tanxs that's just what i wanted.
Logged
Pages: [1] Print 
« previous next »
Jump to:  


Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
header header
header
header