Adding a new attribute to an element: search and replace

Questions about XML that are not covered by the other forums should go here.
mike004
Posts: 18
Joined: Fri Feb 18, 2011 2:29 pm

Adding a new attribute to an element: search and replace

Post by mike004 »

I'm trying to work how to achieve the following using Oxygens "find and replace in files" feature.

Find these elements:

//thead/row/entry

Add an attribute role="col" to each entry element that you find.

//thead/row/entry[@role="col"]

I'm not sure which XML find options to enable.

I used Restrict to XPath: //thead/row/entry

after that I was stumped.
adrian
Posts: 2855
Joined: Tue May 17, 2005 4:01 pm

Re: Adding a new attribute to an element: search and replace

Post by adrian »

Hello,

Oxygen's find/replace features are string/regular expression driven, with some XML filtering.

Restrict to XPath: //thead/row/entry is a good start, this will limit the search domain to entry elements. Note that this only restricts the domain, you still have to search for an actual string(or regular expression).

Text to find: <entry
Replace with: <entry role="col"
Whole word only enabled to avoid partial matches

Press Replace All to perform the replacement.

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
mike004
Posts: 18
Joined: Fri Feb 18, 2011 2:29 pm

Re: Adding a new attribute to an element: search and replace

Post by mike004 »

Thanks, Adrian. that works perfectly.

It's so obvious now...
Post Reply