Finding matching tag

This forum is user-to-user based and not regularly monitored by IDM.
Please see the note at the top of this page on how to contact IDM.

Finding matching tag

Postby brody » Mon Feb 06, 2006 12:52 pm

Hi:

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

ie: <name>........</name>, where picking the first tag (<name>) and you could automatically find the ending tag?

Thanks,

Brody
User avatar
brody
Newbie
 
Posts: 7
Joined: Sat Feb 04, 2006 12:00 am

Re: Finding matching tag

Postby Mofi » Mon Feb 06, 2006 5:01 pm

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

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, with 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.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4036
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Finding matching tag

Postby brody » Tue Feb 07, 2006 12:45 am

Dude:

You are too good.

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

Brody
User avatar
brody
Newbie
 
Posts: 7
Joined: Sat Feb 04, 2006 12:00 am


Return to UltraEdit General Discussion