添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
文雅的鞭炮  ·  第 1 ...·  1 月前    · 
聪明伶俐的课本  ·  SpringBoot ...·  7 月前    · 

Forum Discussion

AngieD18
Contributor
9 years ago

Using Groovy to insert new tag into request. Need help with insert point (XmlParser - FindAll)

Hi. I have a request that I want to change by inserting a new tag after an existing tag.  I am using Groovy code. I have my code working except for one little thing - I can't find where to put the new tag.

Below is my code.  For the findAll() is there an 'it' value that will tell me the index of the item that I am looking at?  In my code I have 5 for my insert point.  This inserts the new tag in after the 5th tag in the parent object. It works but the new tag is not always going to be inserted at the pint.  I need to use a variable for the insert point.  For some reason I am having a hard time finding this answer.

def root = new XmlParser( false, true ).parseText( holder )
fragmentToAdd = new XmlParser( false, true ).parseText( toAdd )  // <tag>value</tag>

root.'**'.findAll() {
if ( it.name().toString().contains( rootNode)) {  //rootNode = An existing tag after which I want to insert the new tag
it.parent().children().add( 5 , fragmentToAdd )  //insert command
}

}

Thank you,

Angie

P.S.

I am using the professional version of soapUI.