Possible to replace multiple text instances based on certain parent text?
-
Hey everyone. First off, I’ve tried searching for this extensively with no luck…with the main problem being i’m really not sure of the verbiage I should be searching for. However, I expect this can be accomplished in some way…i’m just not sure how.
Problem: I have a an entire directory with hundreds of files that need modified. The files are similar to an xml-type format. Essentially what I need to accomplish is to search for a specific number (31553) and replace it with 31554. Easy enough right. I can use the “Find in Files” feature to accomplish this. The issue I am running into is that every instance of 31553 I need to replace, below that in the respective xml attributes I also need to change a 0 to 1 for every instance I replace this in. See below:
Is there a way to accomplish this for an entire file directory? It’s not really feasible for me to mass replace all 31553 with 31554, then go back and update the 0’s to 1…since there will already be existing 31554 entries prior to these changes. There are hundreds of files that require this change, and tens of entries per file. Thanks for any advice here.
-
So this is going to depend upon surrounding data, which can’t be experimented with without a lot of retyping, because you posted a screenshot rather than some textual data.
Try following instructions HERE for possibly better results.
-
Thanks for the advice. So…the original data entries will look similar to this:
<Icon>
<StatusItem item_color_off=“#00ff00” item_color_on=“#ff0000”>
<RealTimeIcon>
<UserDiagramIcon>
<IonIcon resource_id=“51”>
<Caption display_method=“none” caption_position=“8”></Caption>
<Location left=“248” top=“500” bottom=“512” right=“262”></Location>
<Handle>31553</Handle>
<UniqueId>ea6d5d36-0456-43ad-8616-12cb2caa59db</UniqueId>
</IonIcon>
<Node use_parent_link=“0”>USS1A.MDS1A1WL</Node>
</UserDiagramIcon>
<Link type=“1”>
<DDELink>
<Service></Service>
<Topic></Topic>
</DDELink>
</Link>
<DblclickMethod action=“NOTHING”></DblclickMethod>
<DrawBoxInfo border_width=“1”></DrawBoxInfo>
<DisplayType>1</DisplayType>
<CustomImage custom_image_is_multislot=“0” xlink:type=“simple” xlink:href=“x-pml:/diagrams/images/status_graphics/Brkr_V_Withdrawn_Blue.bmp” xmlns:xlink=“http://www.w3.org/1999/xlink”></CustomImage>
<Label display_method=“custom” position=“RIGHT”></Label>
</RealTimeIcon>
<IonClass>21</IonClass>
<Invert>0</Invert>
</StatusItem>
</Icon>
In the end, the <Handle> will need to change to 31554, and the <Invert> will need to change to 1. See below:
<Icon>
<StatusItem item_color_off=“#00ff00” item_color_on=“#ff0000”>
<RealTimeIcon>
<UserDiagramIcon>
<IonIcon resource_id=“51”>
<Caption display_method=“none” caption_position=“8”></Caption>
<Location left=“248” top=“500” bottom=“512” right=“262”></Location>
<Handle>31554</Handle>
<UniqueId>ea6d5d36-0456-43ad-8616-12cb2caa59db</UniqueId>
</IonIcon>
<Node use_parent_link=“0”>USS1A.MDS1A1WL</Node>
</UserDiagramIcon>
<Link type=“1”>
<DDELink>
<Service></Service>
<Topic></Topic>
</DDELink>
</Link>
<DblclickMethod action=“NOTHING”></DblclickMethod>
<DrawBoxInfo border_width=“1”></DrawBoxInfo>
<DisplayType>1</DisplayType>
<CustomImage custom_image_is_multislot=“0” xlink:type=“simple” xlink:href=“x-pml:/diagrams/images/status_graphics/Brkr_V_Withdrawn_Blue.bmp” xmlns:xlink=“http://www.w3.org/1999/xlink”></CustomImage>
<Label display_method=“custom” position=“RIGHT”></Label>
</RealTimeIcon>
<IonClass>21</IonClass>
<Invert>1</Invert>
</StatusItem>
These 2 changes will need to be implemented for hundreds of repeating entries per file.
-
So maybe what you didn’t explicitly say is that the 2 areas of change are a “Handle” with a certain value and an “Invert” value of zero…both within the same “StatusItem” and “/StatusItem” hierarchy?
-
@alan-kilborn That is correct. This hierarchy <Icon> will repeat back to back throughout the document, each containing unique handles. I am only modifying the instances where the handle currently equals 31553.
-
So there’s an established technique for that.
You seem to be pretty detail oriented, so give it a whirl and see if you can make it work.
If not, post back again.
Here’s the posting with the technique: https://community.notepad-plus-plus.org/post/62799 -
@alan-kilborn Thank you. This is what I was anticipating after searching around a bit. I’ll take some time to familiarize myself with this and see if I can get it to work.