Find line including string, copy this line and replace numbers in xml fie
-
Hello,
is there any chance in notepad++ to manipulate an xml file in the following manner?the xml file contains multiple lines an different positions conraining the string “>NAME”
The whole line containing this string should be copied directly behind the found line.The same line contains a string "layer=“25"”
After the copying process there are existing always two identical lines with the same content.
In every second line containing "layer=“25"” the “25” should be replaced by “21”.I only managed up to now to bookmark the linemincluding “>NAME” with the Find/Mark Function .
Thanks for your help!
best regards -
Does
>NAME
come beforelayer="25"
in a line? (for example,<component name=">NAME" layer="25">
) or is it reversed? (for example,<shape type="circle" layer="25">NAME CircleOne</shape>
)I’ll assume the second case as that’s more typical with XML files.
Find:
(?-s)^((.*? layer=")(25)(".*?>NAME.*\R))
Replace with:\1\221\4
Example Input:
<?xml version="1.0" encoding="UTF-8"?> ><document> > <shapes> > <shape type="circle" layer="25">NAME CircleOne</shape> > <shape type="square" layer="25">NAME SquareOne</shape> > <shape type="triangle" layer="25">NAME TriangleOne</shape> > <shape type="hexagon" layer="25">NAME HexagonOne</shape> > </shapes> > <layers> > <layer id="1" layer="25">NAME LayerOne</layer> > <layer id="2" layer="25">NAME LayerTwo</layer> > <layer id="3" layer="25">NAME LayerThree</layer> > <layer id="4" layer="25">NAME LayerFour</layer> > </layers> > <components> > <component id="A" layer="25">NAME ComponentA</component> > <component id="B" layer="25">NAME ComponentB</component> > <component id="C" layer="25">NAME ComponentC</component> > <component id="D" layer="25">NAME ComponentD</component> > </components> ></document>
Output:
<?xml version="1.0" encoding="UTF-8"?> <document> <shapes> <shape type="circle" layer="25">NAME CircleOne</shape> <shape type="circle" layer="21">NAME CircleOne</shape> <shape type="square" layer="25">NAME SquareOne</shape> <shape type="square" layer="21">NAME SquareOne</shape> <shape type="triangle" layer="25">NAME TriangleOne</shape> <shape type="triangle" layer="21">NAME TriangleOne</shape> <shape type="hexagon" layer="25">NAME HexagonOne</shape> <shape type="hexagon" layer="21">NAME HexagonOne</shape> </shapes> <layers> <layer id="1" layer="25">NAME LayerOne</layer> <layer id="1" layer="21">NAME LayerOne</layer> <layer id="2" layer="25">NAME LayerTwo</layer> <layer id="2" layer="21">NAME LayerTwo</layer> <layer id="3" layer="25">NAME LayerThree</layer> <layer id="3" layer="21">NAME LayerThree</layer> <layer id="4" layer="25">NAME LayerFour</layer> <layer id="4" layer="21">NAME LayerFour</layer> </layers> <components> <component id="A" layer="25">NAME ComponentA</component> <component id="A" layer="21">NAME ComponentA</component> <component id="B" layer="25">NAME ComponentB</component> <component id="B" layer="21">NAME ComponentB</component> <component id="C" layer="25">NAME ComponentC</component> <component id="C" layer="21">NAME ComponentC</component> <component id="D" layer="25">NAME ComponentD</component> <component id="D" layer="21">NAME ComponentD</component> </components> </document>
If, for some reason,
>NAME
always precedeslayer="25"
, then just swap the elements in the regex like this:(?-s)^((.*?>NAME.*? layer=")(25)(".*\R))
-
@pbarney Thanks for your reply!
I will check your suggestion tomorrow and will reply,
Best regards