Function overview
Prototype
HTML_Parser_FindOpeningTagPosition_AtCurrentLevel (
html; tag; occurrence; pos )
Parameters
html The html string you are parsing
tag The name of your tag e.g. "table". This should not include any braces e.g. "<"
occurrence The occurrence of the tag you're after... e.g. 1
pos The position in the html you are starting from
Description
Tags:
XML Text Parsing HTML
Retrieves the requested occurrence of the top most set of tag's (see example).
Examples
Sample input
HTML_Parser_FindOpeningTagPosition_AtCurrentLevel( "<div><div><div><span>1</span></div></div></div><div><span>2</span></div>" ; "div" ;2 ; 1 )
Sample output
48
Function code
Let([
start_tag_position = Position ( Lower(html) ; "<" & Lower(tag) ; pos ; 1 );
end_tag_position_start = HTML_Parser_FindClosingTagPosition ( Lower(html) ; tag ; start_tag_position ; 0 );
end_tag_position_end = Position( Lower(html) ; ">" ; end_tag_position_start ; 1 )
];
Case(
//If we don't find anything, we quit and return -1 to indicate nothing was found
start_tag_position = 0 ; -1 ;
//If we've reached the target occurrence, (and a tag was found) we quit with the position of the tag
occurrence = 1 ; start_tag_position ;
//We increment the occurrence and update the position
HTML_Parser_FindOpeningTagPosition_AtCurrentLevel( html ; tag ; occurrence - 1 ; end_tag_position_end )
)
)
// ===================================
/*
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/285
Prototype: HTML_Parser_FindOpeningTagPosition_AtCurrentLevel( html; tag; occurrence; pos )
Function Author: Genx (http://www.fmfunctions.com/mid/29)
Last updated: 05 December 2010
Version: 1
*/
// ===================================
Let([__LITBR__start_tag_position = Position ( Lower(html) ; "<" & Lower(tag) ; pos ; 1 );__LITBR__end_tag_position_start = HTML_Parser_FindClosingTagPosition ( Lower(html) ; tag ; start_tag_position ; 0 );__LITBR__end_tag_position_end = Position( Lower(html) ; ">" ; end_tag_position_start ; 1 )__LITBR__];__LITBR____LITBR__Case( __LITBR__ //If we don't find anything, we quit and return -1 to indicate nothing was found__LITBR__ start_tag_position = 0 ; -1 ; __LITBR____LITBR__ //If we've reached the target occurrence, (and a tag was found) we quit with the position of the tag__LITBR__ occurrence = 1 ; start_tag_position ;__LITBR____LITBR__ //We increment the occurrence and update the position__LITBR__HTML_Parser_FindOpeningTagPosition_AtCurrentLevel( html ; tag ; occurrence - 1 ; end_tag_position_end )__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/285__LITBR____LITBR__ Prototype: HTML_Parser_FindOpeningTagPosition_AtCurrentLevel( html; tag; occurrence; pos )__LITBR__ Function Author: Genx (http://www.fmfunctions.com/mid/29)__LITBR__ Last updated: 05 December 2010__LITBR__ Version: 1__LITBR____LITBR__*/__LITBR__// ===================================