• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Groovy - XML script to modify a node's name and add an attribute.

 
Bill Lee
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am attempting to write a parser which would replace the <Line2 FirstName="Bill" MiddleName="" LastName="Thatcher"/> to
<AddressLine2 Title="Mr" FirstName="Bill" MiddleName="" LastName="Thatcher"/> . In other words, it would replace Line2 with AddressLine2 and add the attribute Title to it. The furthest I have gotten so far is removing Line2. Does anyone have any suggestions? Thanks.


<StreetAddress>
<Address>
<AddressLine1 />
<Line2 FirstName="Bill" MiddleName="" LastName="Thatcher"/>
</Address>
</StreetAddress>
 
Freddy Wong
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Get the attributes of element AddressLine1 and create a new element Line1 with attributes of AddressLine1 and use replaceChild(newChild, oldChild) or something of that sort.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic