newbie0007
newbie0007

Reputation: 47

Find Xml tags based on specific inner tag

I have an xml file which contains tags. I want to delete all <value> tags from the file which contains an inner <isActive> tag. I am trying this with regex find and replace in Notepad++.

I created this regex and i am not able to proceed further.

<value>.*?</value>

Below is the sample xml file`

<value>
                <fullName>CMT - AAPAC - ANZ - Telstra - Media</fullName>
                <default>false</default>
                <label>CMT - AAPAC - ANZ - Telstra - Media</label>
            </value>
            <value>
                <fullName>CMT - AAPAC - ASEAN - C&amp;M - Comms</fullName>
                <default>false</default>
                <isActive>false</isActive>
                <label>CMT - AAPAC - ASEAN - C&amp;M - Comms</label>
            </value>

The output of the file after removing should look like below

<value>
                <fullName>CMT - AAPAC - ANZ - Telstra - Media</fullName>
                <default>false</default>
                <label>CMT - AAPAC - ANZ - Telstra - Media</label>
            </value>

Upvotes: 1

Views: 567

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 627292

You can use

FindWhat: (?s)<value>(?:(?!<value>).)*?<isActive>.*?</value>
Replace With: (empty string)

See the regex demo online. Details:

  • (?s) - . matches newline mode on
  • <value> - a string
  • (?:(?!<value>).)*? - any char, zero or more occurrences, but as few as possible, that does not start value substring
  • <isActive> - a string
  • .*? - any zero or more chars, as few as possible
  • </value> - a string.

See demo and settings:

enter image description here

Upvotes: 1

Related Questions