Simultanious Find and Replace of Tag Pairs

Questions about XML that are not covered by the other forums should go here.
EmelineDehnReynolds
Posts: 1
Joined: Wed Jan 31, 2018 5:08 pm

Simultanious Find and Replace of Tag Pairs

Post by EmelineDehnReynolds » Wed Jan 31, 2018 5:18 pm

Hello Good People of Oxygen,

Is it possible to replace the opening and closing tag at the same time, i.e., change <p>[text]</p> to <item>[text]</item> in one fell swoop within a portion of the document? If so how?

I know I could replace the opening then the closing tags across the text by doing first <p> -> <item> and then </p> -> </item>, but since I'm only doing small chucks of text at a time this is quite time-intensive. I don't want to work with find & replace over the entire scope of the document because there are some <p>[text]</p> tag pairs I'd like to keep as they are.

Thank you,
Emeline Dehn-Reynolds

adrian
Posts: 2580
Joined: Tue May 17, 2005 4:01 pm

Re: Simultanious Find and Replace of Tag Pairs

Post by adrian » Wed Jan 31, 2018 5:40 pm

Hi,

If you specifically just want to change both tags of (basically rename) an element, you can right click on either of the start or end tags and pick Refactoring > Rename Element.... In the Rename dialog you can control if this will be done on just the current element, all its siblings or all elements with the same name in the entire document.

If you want to use the Find/Replace tool, you can use a regular expression.
Find: <p>(.*?)</p>
Replace with: <item>$1</item>
Options > [x] Regular expression
Basically $1 points to the 1st capturing group (first group of parenthesis).

If you have nested p elements it's a bit more complicated, but I expect this isn't the case.

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

Post Reply