Finding matching HTML/XML tag

Finding matching HTML/XML tag

7
NewbieNewbie
7

    Feb 06, 2006#1

    Hi:

    Is there a function similar to find matching brace that finds a matching XML tag?

    For example <name> ... </name> where picking the first tag (<name>) and you could automatically find the ending tag?

    Thanks, Brody

    6,686585
    Grand MasterGrand Master
    6,686585

      Feb 06, 2006#2

      Yes and no. You could modify the open and closing brace strings in the wordfile for the XML language. Example:

      /Open Brace Strings =  "{" "(" "[" "<name>" "<"
      /Close Brace Strings = "}" ")" "]" "</name>" ">"


      See Highlight matching HTML tag for a complete brace strings definition.

      Don't know if this really works. I have not tested it. But I think you will have problems with a big number of tags for brace matching.

      But something similar to match brace can be done with a macro. Let's say you have set the cursor anywhere inside start tag "name". The macro selects the current word and searches for the ending tag with or without selection of the whole text between the 2 tags. Disadvantage of the macro solution: the cursor is set to end of the closing tag and it does not work for nested tags.

      Macro to find end tag with selection:

      ColumnModeOff
      HexOff
      SelectWord
      Find MatchCase Select "</^s>"


      Macro to find end tag without selection:

      ColumnModeOff
      HexOff
      SelectWord
      Find MatchCase "</^s>"


      Macro to find start tag with selection:

      ColumnModeOff
      HexOff
      SelectWord
      Find MatchCase Up Select "<^s>"


      Macro to find start tag without selection:

      ColumnModeOff
      HexOff
      SelectWord
      Find MatchCase Up "<^s>"


      It's possible to improve this quick and dirty macros and create only 1 macro which works for start and end tag automatically by detecting on which tag the cursor is currently set. And it could be also modified to allow the cursor to be set on < or / or > and it nevertheless finds the "matching" tag.
      Best regards from an UC/UE/UES for Windows user from Austria

      7
      NewbieNewbie
      7

        Feb 07, 2006#3

        Dude:

        You are too good.

        Thanks for another answer that is more complete than I could have hoped for, and unbelievably fast.

        Brody

        23
        Basic UserBasic User
        23

          Jul 13, 2017#4

          Anyone know if a "matching tag" solution for UltraEdit exists? (The last response in this thread is from 11 years ago.)

          I'm asking because I've used HomeSite/ColdFusion Studio since 1997 and it stopped being updated 14 years ago. I'm now migrating to UltraEdit and this is one of the few features I haven't been able to replicate using templates (or AutoHotKey).

          HomeSite's Find Matching Tag feature (CTRL+M hotkey) would automatically relocate the focus to the matching start/end tag (versus simply highlighting them.) This became an easy way to quickly navigate code.

          http://www.webmasterworld.com/html/3899956.htm
          http://whatsonyourbrain.com/2007/10/02/ ... html-tags/
          http://www.coffeecup.com/forums/html-ed ... t_id=86135

          Dreamweaver (which has the earlier HTML editor based on HomeSite) has similar features, but may not have this feature anymore (at least not in the "CC 2017" version) according to http://stackoverflow.com/a/4607402/693068

          6,686585
          Grand MasterGrand Master
          6,686585

            Jul 14, 2017#5

            Some HTML/XML related features have been added since 2006. There is now the feature to highlight matching HTML/XML tag as it can be read at Highlight matching HTML tag and of course code folding (for block elements) is also helpful on good structured HTML files.

            But there is still no Go to to matching tag and also no Select to matching tag for HTML, XHTML and XML files although that should be not too difficult to implement by the developers of UltraEdit and UEStudio as the Display XML/HTML tag highlighting already finds out what is the matching tag. It looks like not enough users of UE/UES requested such commands specific for HTML/XHTML/XML.

            However, the Go to to matching brace and Select to matching brace commands with the modification of html.uew opened via Advanced - Settings or Configuration - Editor Display - Syntax Highlighting as described by me at Highlight matching HTML tag works fine for my needs since many years. That's the reason why I have never requested Go to to matching tag and Select to matching tag commands by email to IDM support.

            Users like Robert Mark Bram or Rob Dawson wrote macros and scripts like UltraEdit macro to select HTML/XML tag or UltraEdit Tag Completion Script (see also HTML/XML tag completion in UEStudio '11) which I don't use for myself.

            The XML manager could be also helpful in some cases also for HTML file if the HTML file is well structured, i.e. closing tags which are according to HTML standard are optional like </p> or </li> are present in HTML file (as required for XHTML). A file is parsed for XML manager view by default only if being an XML file, but it is possible to right click into XML manager view and left click in opened context menu on Parse document to use the XML manager on an opened HTML file.
            Best regards from an UC/UE/UES for Windows user from Austria

            23
            Basic UserBasic User
            23

              Jul 15, 2017#6

              Hmmm ... that's close, but not the HomeSite feature that I've been enjoying since since 1997. (I read your post prior and tried the matching brace function prior to posting.)

              The "Find Matching Tag" (CTRL+M) shortcut that was in the Macromedia product would relocate the editing caret to the start/end tag and not 1) select everything between both tags or 2) simply highlight the other tag. It was an extremely simple means to quickly navigate to the start/end tag-based element.

              It also didn't need to start with the focus specifically at the first character of the tag or require that the tag have (or not have) any attributes.

              Code folding is cool, but it collapses/expands segments, but doesn't relocate the focus.

              I could go to any <div*>, <table*> or even <tr*> tag and quickly navigate to the matching start/end tag.

              Maybe I'll get accustomed to not having this feature and retrain myself, but right now it takes me a lot longer to navigate around a document without using the single keypress I've been using for the last 20 years.

              6,686585
              Grand MasterGrand Master
              6,686585

                Jul 16, 2017#7

                The command Go to matching brace moves the caret blinking left of for example <div ...> to > of matching </div>. And with caret blinking left of </div> the caret is moved left of matching <div ...> on using this command.

                That is not as good as the Go to matching brace is in languages like C/C++ with the definition:

                Code: Select all

                /Open Brace Strings =  "{" "(" "["
                /Close Brace Strings = "}" ")" "]"
                For C/C++ the command can be executed anywhere and it moves the caret to matching close/open brace strings. That does not work with the open/close brace strings as I posted in the referenced topic for HTML. The caret must be placed at begin of an open/close tag.

                However, I suggest that you send a feature request for Go to to matching tag and also Select to matching tag for HTML, XHTML and XML files by email to IDM support. The more users request a feature the higher becomes the priority for implementation.
                Best regards from an UC/UE/UES for Windows user from Austria