HTML_Parser_GetTagContents_AtCurrentLevel ( )

Function stats

Average user rating
29
286
9999
Support
FileMaker 7.0 +
Date posted
05 December 2010
Last updated
07 December 2010
Version
Recursive function
No

Author Info
 Genx

18 functions

Average Rating 4.1

author_avatar



 

Function overview

Prototype

HTML_Parser_GetTagContents_AtCurrentLevel  ( html;   tag;   occurrence;   include_tags )


Parameters

html  The html string you are parsing


tag  The name of your tag e.g.


occurrence  The occurrence of the tag you're after... e.g. 1


include_tags  Whether or not to include the enclosing tags in the returned content


Description

Tags:  XML   Text Parsing   HTML  

Similar to the HTML_Parser_GetTagContents function which retrieves contents of a particular occurrence of an html tag but instead takes into account the top most instances of the tags only.

This function ignores any attributes that may be on the tag you're after and retrieves the requested occurrence of the top most set of tag's (see example).

Useful for parsing lists and table rows.

Examples

Sample input

HTML_Parser_GetTagContents_AtCurrentLevel( "<div><div><div><span>1</span></div></div></div><div><span>2</span></div>" ; "div" ;2 ; 1 )


Sample output

<div><span>2</span></div>

 

Function code

Let([
start_tag_position_start = HTML_Parser_FindOpeningTagPosition_AtCurrentLevel ( html ; tag ; occurrence ; 1 );
start_tag_position_end = Position( Lower(html) ; ">" ; start_tag_position_start ; 1 );
end_tag_position_start = HTML_Parser_FindClosingTagPosition ( html ; tag ; start_tag_position_end ; 1 );
end_tag_position_end = Position( Lower(html) ; ">" ; end_tag_position_start ; 1 )
];

If( include_tags = 1 ;
Middle( html ; start_tag_position_start ; end_tag_position_end - start_tag_position_start + 1 ) ;
Middle( html ; start_tag_position_end +1 ; end_tag_position_start - start_tag_position_end - 1 )
)

)

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

    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/286

    Prototype: HTML_Parser_GetTagContents_AtCurrentLevel( html; tag; occurrence; include_tags )
    Function Author: Genx (http://www.fmfunctions.com/mid/29)
    Last updated: 07 December 2010
    Version: 1.2

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