find and replace with line break in multiple files

Having trouble installing Oxygen? Got a bug to report? Post it all here.
Wolfhart
Posts: 37
Joined: Tue Mar 27, 2007 5:46 am

find and replace with line break in multiple files

Post by Wolfhart »

Hi,

The "Find/Replace" dialog when working on the current file allows for inserting line breaks but the "Find/Replace in Files" dialog does not. Why is that? Is there a way to insert line breaks in multiple files? For example, how could I replace the text

abc/><xyz

with

abc/>
<xyz

in all the files in my project?

Thanks,
Wolfhart
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: find and replace with line break in multiple files

Post by sorin_ristache »

Hello,

As you can read in the tooltip of the Replace field you have to use {$NEWLINE} in the replace expression where you want to insert a newline character.


Regards,
Sorin
Wolfhart
Posts: 37
Joined: Tue Mar 27, 2007 5:46 am

Re: find and replace with line break in multiple files

Post by Wolfhart »

Thanks!
Wolfhart
Wolfhart
Posts: 37
Joined: Tue Mar 27, 2007 5:46 am

Re: find and replace with line break in multiple files

Post by Wolfhart »

Hi again,

One more question: What if I want to reverse the above step, that is, replace

abc/>
<xyz

with

abc/><xyz

in all files in my project? I tried Text to find="abc/>{$NEWLINE}<xyz" and Replace with="abc/><xyz", but that doesn't work.

Thanks,
Wolfhart
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: find and replace with line break in multiple files

Post by sorin_ristache »

That is not possible in the current version because the find expression of the Find/Replace in Files dialog can cover only one line. We plan to enhance it in a future version to cover multiple lines as in the Find/Replace dialog used in a single file (the action from menu Find -> Find/Replace). We will let you know when we will have implemented it.


Regards,
Sorin
mandapizz
Posts: 6
Joined: Wed Nov 15, 2017 9:59 pm

Re: find and replace with line break in multiple files

Post by mandapizz »

Hello- has this been fixed/added yet? (your last response)
Radu
Posts: 9055
Joined: Fri Jul 09, 2004 5:18 pm

Re: find and replace with line break in multiple files

Post by Radu »

Hi,

Recent versions of Oxygen allow you to search and replace with full multi-line support.
If this does not work for you maybe you can tell us what version of Oxygen you are using and give a small example about what you are trying to do.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
mandapizz
Posts: 6
Joined: Wed Nov 15, 2017 9:59 pm

Re: find and replace with line break in multiple files

Post by mandapizz »

Hi,

I'm trying to find and replace (with a space, so trying to find and delete) an element that covers multiple lines:
<mods:subject authority="lcsh">
<mods:name type="corporate">
<mods:namePart>InsertNameHere</mods:namePart>
</mods:name>
<mods:topic>Literary collections</mods:topic>
</mods:subject>
I'm using version 20.0. When I try to insert all of this into the find and replace dialog (for multiple files) it only includes the first line: <mods:subject authority="lcsh">

Is there a way to do what I'm hoping to?

Thank you,
Amanda
Radu
Posts: 9055
Joined: Fri Jul 09, 2004 5:18 pm

Re: find and replace with line break in multiple files

Post by Radu »

Hi Amanda,

In the Find field you can insert the entire set of tags on one line separated by a single space between the tag names:

Code: Select all

<mods:subject authority="lcsh"> <mods:name type="corporate"> <mods:namePart>InsertNameHere</mods:namePart> </mods:name> <mods:topic>Literary collections</mods:topic> </mods:subject>
and then check the "Ignore Extra Whitespaces" checkbox.

Or fo to the top level Tools menu->XML Refactoring->"Delete element" and use as XPath something like:

Code: Select all

//*:subject[@authority='lcsh'][*:name[@type='corporate'][*:namePart[text() = 'InsertNameHere']]]
I usually consider that XML-aware changes (which involve searching for entire XML elements) should be best done with the XML Refactoring tools because they should find your element no matter how many whitespaces or line breaks you have between the tags of the element.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
mandapizz
Posts: 6
Joined: Wed Nov 15, 2017 9:59 pm

Re: find and replace with line break in multiple files

Post by mandapizz »

This is great, thank you so much!
Post Reply