Find/Replace in Files for Multiple Lines in an XML file
Questions about XML that are not covered by the other forums should go here.
-
- Posts: 1
- Joined: Wed May 04, 2022 3:33 am
Find/Replace in Files for Multiple Lines in an XML file
Hi all,
I am working on a metadata clean up project. I need to make the same specific changes to dozens and sometimes hundreds of record in batches. I am having issues using the Find/Replace in files function when I have to make changes to the structure of the metadata. The single file find/replace works well in that I can locate an entire structured metadata element and modify or delete. When I use the Fine/Replace in files function, it will only let me find and replace the first line of text from the XML document.
I want to delete the data in the element where null is the value. In the example below I want to remove all of the following lines from a dozen records:
But when I do Search/Replace in flies, the Text to find text box will only let me include the first line <mods:name type="corporate" authority="local"> as the text to search for,
I cannot seem to figure out how to searching across multiple lines across multiple files. Any help would be appreciated.
Thanks,
Mike
I am working on a metadata clean up project. I need to make the same specific changes to dozens and sometimes hundreds of record in batches. I am having issues using the Find/Replace in files function when I have to make changes to the structure of the metadata. The single file find/replace works well in that I can locate an entire structured metadata element and modify or delete. When I use the Fine/Replace in files function, it will only let me find and replace the first line of text from the XML document.
I want to delete the data in the element where null is the value. In the example below I want to remove all of the following lines from a dozen records:
Code: Select all
<mods:name type="corporate" authority="local">
<mods:namePart>null</mods:namePart>
<mods:role>
<mods:roleTerm type="text" authority="marcrelator">null</mods:roleTerm>
</mods:role>
</mods:name>
I cannot seem to figure out how to searching across multiple lines across multiple files. Any help would be appreciated.
Thanks,
Mike
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: Find/Replace in Files for Multiple Lines in an XML file
Hi,
You can use \n in the "Text to find" box to indicate a new line or \s for any whitespace (line breaks, tabs and spaces). The "Regular expression" box is required in this case.
So, if you really want to do this via Find/Replace in Files you should search for:
\Qtext\E means the searched text is "literal" (not a regular expression).
e.g.
Note that Find/Replace in Files may not be the tool best suited for this job. But I guess it can get the job done if used right.
Regards,
Adrian
You can use \n in the "Text to find" box to indicate a new line or \s for any whitespace (line breaks, tabs and spaces). The "Regular expression" box is required in this case.
So, if you really want to do this via Find/Replace in Files you should search for:
Code: Select all
^\s*\Qline1\E\s*\Qline2\E .... \s*\QlineN\E
e.g.
Code: Select all
^\s*\Q<mods:name type="corporate" authority="local">\E\s*\Q<mods:namePart>null</mods:namePart>\E\s*\Q<mods:role>\E\s*\Q<mods:roleTerm type="text" authority="marcrelator">null</mods:roleTerm>\E\s*\Q</mods:role>\E\s*\Q</mods:name>\E
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Return to “General XML Questions”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service