HTML_Parser_FindOpeningTagPosition_AtCurrentLevel ( )

Function stats

Average user rating
29
285
9999
Support
FileMaker 7.0 +
Date posted
05 December 2010
Version
1
Recursive function
Yes

Author Info
 Genx

18 functions

Average Rating 4.1

author_avatar



 

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

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