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 :)
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login