HTML_Parser_GetTagContents ( )

Function stats

Average user rating
29
284
9999
Support
FileMaker 7.0 +
Date posted
02 December 2010
Version
1
Recursive function
No

Author Info
 Genx

18 functions

Average Rating 4.1

author_avatar



 

Function overview

Prototype

HTML_Parser_GetTagContents  ( html;   tag;   occurrence;   include_tags )


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


include_tags  Whether or not to include the tags in your final content. Setting this to 0 will get you the inner contents of the tag. Setting this to 1 will get you the inner contents of the tag and wrapping tag itself (see examples)


Description

Tags:  XML   Text Parsing   HTML  

Retrieves contents of a particular occurrence of an html tag.

This function takes into account that additional start / end tags of the same name may exist within the tag contents (and thus isolates the correct ending tag) and additionally ignores any attributes that may be on the tag you're after.

Note that helper function is recursive.

Examples

Sample input

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

HTML_Parser_GetTagContents ( "<html><table><tr><td><table>Test</table></td></tr></table></html>" ; "table" ; 1 ; 0 )


Sample output

<table><tr><td><table>Test</table></td></tr></table>

<tr><td><table>Test</table></td></tr>

 

Function code

Let([
start_tag_position_start = Position ( Lower(html) ; "<" & Lower(tag) ; 0 ; occurrence );
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/284

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

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