• Login
Community
  • Login

Find and replace specific word between more tags

Scheduled Pinned Locked Moved General Discussion
6 Posts 4 Posters 523 Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P
    plidos
    last edited by Nov 29, 2019, 6:44 PM

    Hello,
    Im using notepad ++ and i dont know how to do find+replace operation

    I have this kind of string

    <Item UPC=“1234”><Pictures><Picture Resolution=“1024” ID=“1”>somepicture.gif</Picture></Pictures><IsVisible>True</IsVisible></Item>

    And i want to change <IsVisible>True</IsVisible> to <IsVisible>False</IsVisible>

    Can you please help me? How can i do this?

    Thanks a lot!

    1 Reply Last reply Reply Quote 0
    • P
      plidos
      last edited by Nov 29, 2019, 6:50 PM

      @plidos said in Find and replace specific word between more tags:

      Sorry correct string is

      <Item UPC=“1234”><Pictures><Picture Resolution=“1024” ID=“1”>somepicture.gif</Picture><moretags>…</moretags></Pictures><IsVisible>True</IsVisible><moretags>…</moretags></Item>

      Thanks!

      1 Reply Last reply Reply Quote 0
      • E
        Ekopalypse
        last edited by Nov 29, 2019, 6:54 PM

        @plidos said in Find and replace specific word between more tags:

        <IsVisible>True</IsVisible> to <IsVisible>False</IsVisible>

        The obvious answer to your question would be to use
        find what: <IsVisible>True</IsVisible>
        replace with: <IsVisible>False</IsVisible>

        P 1 Reply Last reply Dec 2, 2019, 7:39 PM Reply Quote 3
        • P
          plidos @Ekopalypse
          last edited by Dec 2, 2019, 7:39 PM

          @Ekopalypse
          yes this is simple but in that file i have over maybe 200 tags starting with <Item UPC=“(random numbers)”> so i need to change ```
          <IsVisible>True</IsVisible>

          <Item UPC=“1234”>. It is identified by <Item UPC=“1234”>
          
          So for example i need to change <IsVisible>True</IsVisible> to <IsVisible>False</IsVisible> only for tag <Item UPC="1234"> (not for 1235)
          

          <Item UPC=“1234”><Pictures><Picture Resolution=“1024” ID=“1”>somepicture.gif</Picture><moretags>…</moretags></Pictures><IsVisible>True</IsVisible><moretags>…</moretags></Item>

          
          
          Thanks
          A D 2 Replies Last reply Dec 2, 2019, 8:07 PM Reply Quote 1
          • A
            Alan Kilborn @plidos
            last edited by Dec 2, 2019, 8:07 PM

            @plidos

            Probably the most simplistic approach would do it:

            Search for (<Item UPC=“1234”>.*?<IsVisible>)False(</IsVisible>.*?</Item>)
            and replace with \1True\2
            using Regular Expression search mode.

            There are more complicated ways which are more rigorous, but perhaps we don’t need to go there…

            1 Reply Last reply Reply Quote 4
            • D
              dinkumoil @plidos
              last edited by dinkumoil Dec 2, 2019, 10:33 PM Dec 2, 2019, 10:20 PM

              @plidos

              You could install the XML Tools plugin and use its XSLT Transformation feature.

              1. Open Plugins Admin and install XML Tools plugin.
              2. After Notepad++ has been restarted paste the XSLT code from below to an empty tab and save it for example as ChangeVisible.xsl.
              3. Open the XML file you want to process.
              4. Go to (menu) Plugins -> XML Tools -> XSLT Transformation.
              5. In the dialog popping up click on the ellipsis button and in the file selector dialog popping up select the XSL file you created in step 2.
              6. In the options field of the dialog type UPCid='1234'.
              7. Click the Transform button.
              8. A new document will be opened with your changes applied. Save it to the original file.

              To change the value of the IsVisible node of more than one Item nodes, repeat steps 6 to 8.

              The XSLT code. Please note: In line 19 (<xsl:template match="/RootNode/Item/IsVisible">) you have to provide the complete path to the IsVisible XML node, starting from the document’s root node.

              <?xml version="1.0" encoding="UTF-8"?>
              
              <xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
              
                <xsl:output
                  method="xml"
                  omit-xml-declaration="no"
                  indent="yes"
                />
              
                <xsl:param name="UPCid"/>
              
                <xsl:template match="@*|node()">
                  <xsl:copy>
                    <xsl:apply-templates select="@*|node()"/>
                  </xsl:copy>
                </xsl:template>
              
                <xsl:template match="/RootNode/Item/IsVisible">
                  <xsl:choose>
                    <xsl:when test="../@UPC=$UPCid">
                      <xsl:copy>
                        <xsl:copy-of select="@*"/>
                        <xsl:text>False</xsl:text>
                      </xsl:copy>
                    </xsl:when>
                    <xsl:otherwise>
                      <xsl:copy>
                        <xsl:copy-of select="@*|node()"/>
                      </xsl:copy>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:template>
              
              </xsl:transform>
              
              1 Reply Last reply Reply Quote 3
              6 out of 6
              • First post
                6/6
                Last post
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors