XmlSlurper in Groovy and SOAPUI - Add new element to random location in xml -


i'm creating automated tests soapui , need check happens when add new groupingnodes on different positions in xml.

i have xml structure similar this:

<rootnode> <groupingnode>     <id>1</id>     <name>node 1</name>     <groupingnode>         <id>2</id>         <name>node 2</name>         <groupingnode>             <id>3</id>             <name>node 3</name>         </groupingnode>     </groupingnode> </groupingnode> <groupingnode>     <id>4</id>     <name>node 4</name> </groupingnode> 

and new elements add:

<groupingnode>     <id>5</id>     <name>node 5</name> </groupingnode> 

in data source defined several different combinations node , add, new node in 1 test case needs added rootnode, in second test case groupnode id=3, in third test case newly created node added rootnode , on.

so question how can programmatically add new groupingnode element random position in xml.

i first tried depth first find parent groupingnode via name.

xml.'**'.find{groupingnode-> groupingnode.name.text() == parentnode}.appendnode( fragmenttoadd ) 

but didn't work since couldn't found nodes. later found out code can find old nodes, not new ones. , after research found out problem xmlslurper , if want new nodes visible, need evaluate xml again 4.1 adding nodes after creating new node needed is:

def newxml = new streamingmarkupbuilder().bind { mkp.yield xml}.tostring() xml= new xmlslurper( false, true ).parsetext( newxml ) 

and after able find groupingnodes depth first.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -