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
*/
// ===================================
//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__LITBR__Let([__LITBR__next_start_tag_pos = Position ( Lower(html) ; "<" & Lower(tag) ; pos ; 1 );__LITBR__next_end_tag_pos = Position( Lower(html) ; "</" & Lower(tag) & ">" ; pos ; 1 );__LITBR__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 );__LITBR__curindex = If( next_start_tag_pos < next_end_tag_pos and next_start_tag_pos <> 0 ; curindex+1 ; curindex-1 )__LITBR__];__LITBR____LITBR__Case( __LITBR__ curindex = 0 ; next_tag_pos ;__LITBR__ next_tag_pos = 0 ; -1 ;__LITBR__ HTML_Parser_FindClosingTagPosition( html ; tag ; next_tag_pos+1 ; curindex )__LITBR__)__LITBR____LITBR__)__LITBR____LITBR__// ===================================__LITBR__/*__LITBR____LITBR__ This function is published on FileMaker Custom Functions__LITBR__ to check for updates and provide feedback and bug reports__LITBR__ please visit http://www.fmfunctions.com/fid/283__LITBR____LITBR__ Prototype: HTML_Parser_FindClosingTagPosition( html; tag; pos; curindex )__LITBR__ Function Author: Genx (http://www.fmfunctions.com/mid/29)__LITBR__ Last updated: 05 December 2010__LITBR__ Version: 1.1__LITBR____LITBR__*/__LITBR__// ===================================