File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Groovy and the fly likes Groovy - XML script to modify a node's name and add an attribute. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Languages » Groovy
Bookmark "Groovy - XML script to modify a node Watch "Groovy - XML script to modify a node New topic
Author

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

Bill Lee
Greenhorn

Joined: Feb 02, 2007
Posts: 20
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

Joined: Sep 11, 2006
Posts: 959

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.


SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4
My Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Groovy - XML script to modify a node's name and add an attribute.