Community
    • 登入

    Find and replace specific word between more tags

    已排程 已置頂 已鎖定 已移動 General Discussion
    6 貼文 4 Posters 623 瀏覽
    正在載入更多貼文
    • 從舊到新
    • 從新到舊
    • 最多點贊
    回覆
    • 在新貼文中回覆
    登入後回覆
    此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
    • plidosP
      plidos
      最後由 編輯

      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 條回覆 最後回覆 回覆 引用 0
      • plidosP
        plidos
        最後由 編輯

        @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 條回覆 最後回覆 回覆 引用 0
        • EkopalypseE
          Ekopalypse
          最後由 編輯

          @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>

          plidosP 1 條回覆 最後回覆 回覆 引用 3
          • plidosP
            plidos @Ekopalypse
            最後由 編輯

            @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
            Alan KilbornA dinkumoilD 2 條回覆 最後回覆 回覆 引用 1
            • Alan KilbornA
              Alan Kilborn @plidos
              最後由 編輯

              @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 條回覆 最後回覆 回覆 引用 4
              • dinkumoilD
                dinkumoil @plidos
                最後由 dinkumoil 編輯

                @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 條回覆 最後回覆 回覆 引用 3
                • 第一個貼文
                  最後的貼文
                The Community of users of the Notepad++ text editor.
                Powered by NodeBB | Contributors