Changing the closing tag on a XML file, so it matches the opening tag, with notepad++ -
-
I have a issue, i have a big XML file, and using notepad++.
I have this XML syntax:
<wp:postmeta-ingredients> <wp:meta_key><![CDATA[ingredients_list_0_name]]></wp:meta_key> <wp:meta_value><![CDATA[Tészta]]></wp:meta_value> </wp:postmeta>
What i want, is to change the closing tag to:
<wp:postmeta-ingredients> <wp:meta_key><![CDATA[ingredients_list_0_name]]></wp:meta_key> <wp:meta_value><![CDATA[Tészta]]></wp:meta_value> </wp:postmeta-ingredients>
I have other data like this:
<wp:postmeta> <wp:meta_key><![CDATA[ingredients_list_0_ingredients_1_quantity]]></wp:meta_key> <wp:meta_value><![CDATA[2000]]></wp:meta_value> </wp:postmeta>
That i want to keep the same. So its just when the opening tag is starting with:
<wp:postmeta-ingredients>
How do i do this in notepad++, have to be with “replace all”
Thanks.
-
Thank you for showing before and after data, in boxes, with data that should match and data that shouldn’t. It makes your question easier to understand.
If I have
<wp:postmeta-ingredients> <wp:meta_key><![CDATA[ingredients_list_0_name]]></wp:meta_key> <wp:meta_value><![CDATA[Tészta]]></wp:meta_value> </wp:postmeta> <wp:postmeta> <wp:meta_key><![CDATA[ingredients_list_0_ingredients_1_quantity]]></wp:meta_key> <wp:meta_value><![CDATA[2000]]></wp:meta_value> </wp:postmeta> <wp:postmeta-ingredients> <wp:meta_key><![CDATA[ingredients_list_0_name]]></wp:meta_key> <wp:meta_value><![CDATA[Tészta]]></wp:meta_value> </wp:postmeta> <wp:postmeta> <wp:meta_key><![CDATA[ingredients_list_0_ingredients_1_quantity]]></wp:meta_key> <wp:meta_value><![CDATA[2000]]></wp:meta_value> </wp:postmeta>
- FIND =
(?s)<wp:postmeta-ingredients>.*?\K</wp:postmeta>
- REPLACE =
</wp:postmeta-ingredients>
- SEARCH MODE = Regular Expression
- REPLACE ALL (because of \K, hitting REPLACE multiple times will not work)
becomes
<wp:postmeta-ingredients> <wp:meta_key><![CDATA[ingredients_list_0_name]]></wp:meta_key> <wp:meta_value><![CDATA[Tészta]]></wp:meta_value> </wp:postmeta-ingredients> <wp:postmeta> <wp:meta_key><![CDATA[ingredients_list_0_ingredients_1_quantity]]></wp:meta_key> <wp:meta_value><![CDATA[2000]]></wp:meta_value> </wp:postmeta> <wp:postmeta-ingredients> <wp:meta_key><![CDATA[ingredients_list_0_name]]></wp:meta_key> <wp:meta_value><![CDATA[Tészta]]></wp:meta_value> </wp:postmeta-ingredients> <wp:postmeta> <wp:meta_key><![CDATA[ingredients_list_0_ingredients_1_quantity]]></wp:meta_key> <wp:meta_value><![CDATA[2000]]></wp:meta_value> </wp:postmeta>
The regex is looking for
<wp:postmeta-ingredients>
followed by any character(s) before the first</wp:postmeta>
it reaches; then it resets (so all the stuff that’s matched so far will not be replaced), then matches</wp:postmeta>
, and replaces just that last part of the match with</wp:postmeta-ingredients>
.Barring unforeseen on edge cases, I think this should work for you.
- FIND =
-
@peterjones said in Changing the closing tag on a XML file, so it matches the opening tag, with notepad++ -:
FIND = (?s)wp:postmeta-ingredients.*?\K</wp:postmeta>
REPLACE = </wp:postmeta-ingredients>
SEARCH MODE = Regular Expression
REPLACE ALL (because of \K, hitting REPLACE multiple times will not work)Ehh, wow, fast and correct answer, worked like a charm.
Super impress of the quality here.Thank you so much Peter :)