HTML_Parser_FindClosingTagPosition ( )

Function stats

Average user rating
29
283
9999
Support
FileMaker 7.0 +
Date posted
02 December 2010
Last updated
05 December 2010
Version
Recursive function
Yes

Author Info
 Genx

18 functions

Average Rating 4.1

author_avatar



 

Function overview

Prototype

HTML_Parser_FindClosingTagPosition  ( html;   tag;   pos;   curindex )


Parameters

html  The html string you are parsing


tag  The name of your tag e.g.


pos  Current position from which we are starting (should be a position after our start tag)


curindex  Should always be set to 1


Description

Tags:  XML   Text Parsing   HTML  

Given a starting position (being a position immediately following a start html tag), this function finds the position of the corresponding end html tag.

It also takes into account groups of tags that may be contained within the tag (see example).

Examples

Sample input

HTML_Parser_FindClosingTagPosition ( "<html><table><tr><td><table>Test</table></td></tr></table></html>" ; "table" ; 8 ; 1 )


Sample output

51

 

Function code

//Cur Index Should be set as 1 if starting past the beggingin of the start tag, or 0 if starting at or before the starting position of the tag
Let([
next_start_tag_pos = Position ( Lower(html) ; "<" & Lower(tag) ; pos ; 1 );
next_end_tag_pos = Position( Lower(html) ; "</" & Lower(tag) & ">" ; pos ; 1 );
next_tag_pos = If( next_start_tag_pos < next_end_tag_pos and next_start_tag_pos <> 0 ; next_start_tag_pos ; next_end_tag_pos );
curindex = If( next_start_tag_pos < next_end_tag_pos and next_start_tag_pos <> 0 ; curindex+1 ; curindex-1 )
];

Case(
    curindex = 0 ; next_tag_pos ;
    next_tag_pos = 0 ; -1 ;
    HTML_Parser_FindClosingTagPosition( html ; tag ; next_tag_pos+1 ; curindex )
)

)

// ===================================
/*

    This function is published on FileMaker Custom Functions
    to check for updates and provide feedback and bug reports
    please visit http://www.fmfunctions.com/fid/283

    Prototype: HTML_Parser_FindClosingTagPosition( html; tag; pos; curindex )
    Function Author: Genx (http://www.fmfunctions.com/mid/29)
    Last updated: 05 December 2010
    Version: 1.1

*/
// ===================================