Testranger
13 years agoContributor
Insert XML fragment into request object
Hi all,
I have a requirement to insert a parsed XML fragment into a request object.
The parsed XML looks something like this (not exact fragment)
<s:comparable xmlns:s="http://www.w3.org/HTML/1998/html4"
xmlns:xdc="http://www.xml.com/books">
<xdc:transfer>
<xdc:price>$100.00</xdc:price>
<xdc:price>$200.00</xdc:price>
</xdc:transfer>
</s:comparable>
Using groovy, I parse this, using Transformers, StringWriters, etc and store it into a test case property.
Using groovy again, I create a "placement marker" inside the request object. Like:
<s:envelope xmlns:s="http://www.w3.org/HTML/1998/html4"
xmlns:xdc="http://www.xml.com/books">
...
<s:comparable/>
...
</s:envelope>
Using the property transfer feature i create an xpath transfer from the test case property to the request object. It seems to work. The following is created:
<s:envelope xmlns:s="http://www.w3.org/HTML/1998/html4"
xmlns:xdc="http://www.xml.com/books">
...
<s:comparable>
<xdc:transfer>
<xdc:price>$100.00</xdc:price>
<xdc:price>$200.00</xdc:price>
</xdc:transfer>
</s:comparable>
...
</s:envelope>
Note: in property transfer, I have selected "transfer child nodes".
Basically, what I'd like to know is, is there a better way of doing this? Do i even need to use property transfer?
Thanks in advance.
Regards,
Testranger
I have a requirement to insert a parsed XML fragment into a request object.
The parsed XML looks something like this (not exact fragment)
<s:comparable xmlns:s="http://www.w3.org/HTML/1998/html4"
xmlns:xdc="http://www.xml.com/books">
<xdc:transfer>
<xdc:price>$100.00</xdc:price>
<xdc:price>$200.00</xdc:price>
</xdc:transfer>
</s:comparable>
Using groovy, I parse this, using Transformers, StringWriters, etc and store it into a test case property.
Using groovy again, I create a "placement marker" inside the request object. Like:
<s:envelope xmlns:s="http://www.w3.org/HTML/1998/html4"
xmlns:xdc="http://www.xml.com/books">
...
<s:comparable/>
...
</s:envelope>
Using the property transfer feature i create an xpath transfer from the test case property to the request object. It seems to work. The following is created:
<s:envelope xmlns:s="http://www.w3.org/HTML/1998/html4"
xmlns:xdc="http://www.xml.com/books">
...
<s:comparable>
<xdc:transfer>
<xdc:price>$100.00</xdc:price>
<xdc:price>$200.00</xdc:price>
</xdc:transfer>
</s:comparable>
...
</s:envelope>
Note: in property transfer, I have selected "transfer child nodes".
Basically, what I'd like to know is, is there a better way of doing this? Do i even need to use property transfer?
Thanks in advance.
Regards,
Testranger