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 02, 2008, 02:14:00 pm
Username: Password:
Login with username, password and session length

Forgot your password?
 
PLEASE HELP !!!: How to append "repetition" of nodes ?
Welcome, Guest. Please login or register.
December 02, 2008, 02:14:00 pm
Home Help Search Login Register
News: The Forums are up! Welcome to eviware.

+  Eviware Forum
|-+  soapUI
| |-+  soapUI
| | |-+  PLEASE HELP !!!: How to append "repetition" of nodes ?
« previous next »
Pages: [1] Print
Author Topic: PLEASE HELP !!!: How to append "repetition" of nodes ?  (Read 960 times)
Akarui Tomodachi
Newbie
*
Posts: 6


« on: May 26, 2008, 07:41:39 am »

PLEASE HELP !!!!

How to append (insert) element repetition in the default request file ?
 
I have a "default request" as below:
 
/******************* Default request before repeat ***************************
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:prod="http://xyz.ca/ebusiness/ProductServiceWrapper"
xmlns:prod1="http://xyz.ca/ebusiness/ProductService">
<soapenv:Header/>
<soapenv:Body>
<prod:getDistProductDetails>
<prod:request>
<!--1 or more repetitions:-->
<prod1:ProdSet DestCountryCode="?" ContractNumber="?">
<!--Zero or more repetitions:-->
<prod1:ProductServiceId>?</prod1:ProductServiceId>
</prod1:ProdSet>
</prod:request>
</prod:getDistProductDetails>
</soapenv:Body>
</soapenv:Envelope>
****************************************************************************/
 
 
Now, I need to insert (repeatedly) the element "ProductServiceId"  3 times which will look like:
 
/******************* Default request after repeat inserted *****************
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:prod="http://xyz.ca/ebusiness/ProductServiceWrapper
xmlns:prod1="http://xyz.ca/ebusiness/ProductService">
<soapenv:Header/>
<soapenv:Body>
<prod:getDistProductDetails>
<prod:request>
<!--1 or more repetitions:-->
<prod1:ProdSet DestCountryCode="?" ContractNumber="?">
<!--Zero or more repetitions:-->
<prod1:ProductServiceId>?</prod1:ProductServiceId>
<prod1:ProductServiceId>?</prod1:ProductServiceId>
<prod1:ProductServiceId>?</prod1:ProductServiceId>

</prod1:ProdSet>
</prod:request>
</prod:getDistProductDetails>
</soapenv:Body>
</soapenv:Envelope>
****************************************************************************/
 
How can I do it in Groovy ?
I have tried as below, but it is giving me an exception (I know, did something wrong  Angry )

"Mon May 26 02:32:18 EDT 2008:ERROR:groovy.lang.MissingMethodException: No signature of method: groovy.util.NodeList.appendNode() is applicable for argument types: (java.lang.String, java.lang.String) values: {"prod1:ProductServiceId", "?"}"

My code snippet is:
/********************
...
...
def root = new XmlParser().parseText(newRequest)

root["soapenv:Body"]["prod:getDistProductDetails"]["prod:request"]["prod1:ProdSet"].appendNode("prod1:ProductServiceId", "?")

def writer = new StringWriter()
new XmlNodePrinter(new PrintWriter(writer)).print(root)
def result = writer.toString()
...
...
********************/
 
Logged
omatzura
Administrator
Hero Member
*****
Posts: 1,470


« Reply #1 on: May 26, 2008, 09:46:57 am »

Hi!

Try using GroovyUtils/XmlHolder to get the DOM node of the parent ("prod1:request"), and then use the DOMCategory to append the nodes.. something in the line of
Code:
import groovy.xml.dom.DOMCategory
import groovy.xml.QName

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

// get the xml to update
def holder = groovyUtils.getXmlHolder( "Request 1#Request" )

// get parent node for new child
def node = holder.getDomNode( "//prod1:request" )

// use DOMCategory to simplify things..
use( DOMCategory )
{
   // add new "ProductServiceId" element with "?" value..
   node.appendNode( new QName( "http://xyz.ca/ebusiness/ProductService", "ProductServiceId", "prod1"), "?" ) }

holder.updateProperty()

Hope this helps!

regards,

/Ole
eviware.com
Logged
Akarui Tomodachi
Newbie
*
Posts: 6


« Reply #2 on: May 27, 2008, 07:24:16 am »

Hi Ole:
Thanks for your help.
Your code sample worked like a magic.

But I am still having trouble to insert a node with attributes.

For example, below is the XML before inserting node with attributes (in bold):
/******************
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:prod="http://xyz.ca/ebusiness/ProductServiceWrapper" xmlns:prod1="http://xyz.ca/ebusiness/ProductService">
   <soapenv:Header/>
   <soapenv:Body>
      <prod:getDistProductDetails>
         <prod:request>
            <!--1 or more repetitions:-->
            <prod1:ProdSet DestCountryCode="?" ContractNumber="?">
               <!--Zero or more repetitions:-->
               <prod1:ProductServiceId>?</prod1:ProductServiceId>
               <prod1:ProductServiceId>?</prod1:ProductServiceId>
            </prod1:ProdSet>
         </prod:request>
      </prod:getDistProductDetails>
   </soapenv:Body>
</soapenv:Envelope>
*******************/

Now, I like to append the node with attributes and it should look like as below:
/****************
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:prod="http://innovapost.ca/ebusiness/ProductServiceWrapper" xmlns:prod1="http://innovapost.ca/ebusiness/ProductService">
   <soapenv:Header/>
   <soapenv:Body>
      <prod:getDistProductDetails>
         <prod:request>
            <!--1 or more repetitions:-->
            <prod1:ProdSet DestCountryCode="?" ContractNumber="?">
            <prod1:ProdSet DestCountryCode="?" ContractNumber="?">

               <!--Zero or more repetitions:-->
               <prod1:ProductServiceId>?</prod1:ProductServiceId>
               <prod1:ProductServiceId>?</prod1:ProductServiceId>
            </prod1:ProdSet>
         </prod:request>
      </prod:getDistProductDetails>
   </soapenv:Body>
</soapenv:Envelope>
******************/

I tried with many ways after changing the code under the use (DOMCategory) {} but nothing is working. Please give me some hints.

Thanks in advance.
Logged
omatzura
Administrator
Hero Member
*****
Posts: 1,470


« Reply #3 on: May 27, 2008, 08:47:39 am »

Hi!

hm.. should the ProdSet node have no content initially? And should it be inserted as the first child of the request?

regards,

/Ole
eviware.com
Logged
Akarui Tomodachi
Newbie
*
Posts: 6


« Reply #4 on: May 27, 2008, 02:57:39 pm »

Hi Ole:
Thanks for your kind attention into this matter at your busy schedule.
Anyway, actually ProdSet has got the default attributes from the beginning. Here is the default request:

/**************
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:prod="http://xyz.ca/ebusiness/ProductServiceWrapper" xmlns:prod1="http://xyz.ca/ebusiness/ProductService">
   <soapenv:Header/>
   <soapenv:Body>
      <prod:getDistProductDetails>
         <prod:request>
            <!--1 or more repetitions:-->
            <prod1:ProdSet DestCountryCode="?" ContractNumber="?">
      <!--Zero or more repetitions:-->
               <prod1:ProductServiceId>?</prod1:ProductServiceId>
            </prod1:ProdSet>
         </prod:request>
      </prod:getDistProductDetails>
   </soapenv:Body>
</soapenv:Envelope>
**************/
Logged
omatzura
Administrator
Hero Member
*****
Posts: 1,470


« Reply #5 on: May 28, 2008, 08:50:09 pm »

Hi,

sorry, I'm still not exactly sure of what you want to do here.. do you want to add a new ProdSet and contained ProductServiceId elements? Or modify the existing one in the default message? (including the attributes)

regards!

/Ole
eviware.com
Logged
Akarui Tomodachi
Newbie
*
Posts: 6


« Reply #6 on: May 29, 2008, 03:44:27 am »

Hi Ole:
I am sorry for not explaining the problem properly, my apology  Cry
Actually, the comment line ("<!--1 or more repetitions:-->") before the element "<prod1:ProdSet" is a bit confusing.

You are most likely right (and it looks like obvious!) that the repeat of the node "<prod1:ProdSet" will include its two attributes DestCountryCode= ContractNumber= and child node "<prod1:ProductServiceId>" as well. So when I'll repeat the node "prod1:ProdSet" twice, the default request file should look like as below:

I'll confirm this with designer of the WSDL and let you know.
Thanks.

/**************
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:prod="http://xyz.ca/ebusiness/ProductServiceWrapper" xmlns:prod1="http://xyz.ca/ebusiness/ProductService">
   <soapenv:Header/>
   <soapenv:Body>
      <prod:getDistProductDetails>
         <prod:request>

            <!--1 or more repetitions:-->

            <prod1:ProdSet DestCountryCode="?" ContractNumber="?">
               <!--Zero or more repetitions:-->
               <prod1:ProductServiceId>?</prod1:ProductServiceId>
            </prod1:ProdSet>

            <prod1:ProdSet DestCountryCode="?" ContractNumber="?">
               <!--Zero or more repetitions:-->
               <prod1:ProductServiceId>?</prod1:ProductServiceId>
            </prod1:ProdSet>

         </prod:request>
      </prod:getDistProductDetails>
   </soapenv:Body>
</soapenv:Envelope>
**************/

Logged
omatzura
Administrator
Hero Member
*****
Posts: 1,470


« Reply #7 on: May 29, 2008, 08:29:28 am »

Hi!

ok.. so the following code will add a new ProdSet with default attributes and a contained ProductServiceId:
Code:
import groovy.xml.dom.DOMCategory
import groovy.xml.QName

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

// get the xml to update
def holder = groovyUtils.getXmlHolder( "Request 1#Request" )

// get parent node for new child
def node = holder.getDomNode( "//prod1:request" )

// use DOMCategory to simplify things..
use( DOMCategory )
{
   def ns = "http://xyz.ca/ebusiness/ProductService"

   // add new "ProdSet" element..
   def prodSet = node.appendNode( new QName( ns, "ProdSet", "prod1"))

   // set its attributes
  prodSet.setAttribute( "DestCountryCode", "?" )
  prodSet.setAttribute( "ContractNumber", "?" )

  // add new "ProductServiceId" element with "?" value..
   prodSet.appendNode( new QName( ns, "ProductServiceId", "prod1"), "?" ) }

}

holder.updateProperty()

ok?

regards!

/Ole
eviware.com
Logged
Akarui Tomodachi
Newbie
*
Posts: 6


« Reply #8 on: May 29, 2008, 08:49:12 pm »

Hi Ole:
Thanks for your help.
I works exactly the same way I wanted.
Best Regards.

/atomodachi
Logged
Maria Aschauer
Newbie
*
Posts: 1


« Reply #9 on: July 10, 2008, 09:26:30 am »

hi,

I am facing a similar task. I tried your solution, but it still doesn't work:

Code:
// get parent node for new child
def node = holder.getDomNode( "//prod1:request" )


the type of node is org.apache.xmlbeans.impl.store.Xobj$ElementXobj and not as expected of org.w3c.dom.Node...

Logged
omatzura
Administrator
Hero Member
*****
Posts: 1,470


« Reply #10 on: July 10, 2008, 10:00:59 pm »

Hi,

this type implements the org.w3c.dom.Element interface (which extends org.w3c.dom.Node), so you should be able to use it as such..

regards,

/Ole
eviware.com
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