xmlTagN.valuePosEnd ( )

Function stats

Average user rating
224
239
9999
Support
FileMaker 7.0 +
Date posted
13 December 2009
Last updated
13 December 2009
Version
Recursive function
Yes

Author Info
 konrad

10 functions

Average Rating None

author_avatar



 

Function overview

Prototype

xmlTagN.valuePosEnd  ( name;   xml;   N )


Parameters

name  name of the tag to search for


xml  


N  Nth appearance of the start tag


Description

Tags:  xml  

-- is part of xmlGetH / xmlSetH ---

Examples

Sample input

xmlTagN.valuePosEnd ( "ID" ; xml ; 1 )
where xml = "<contact><ID>2354</ID><Lastname>Frank</Lastname></contact>"


Sample output

17

 

Function code

//search position of the corresponding end tag for the N-th start tag with the given name
//result ist the position of the last character bevor the searched end tag

Let([

tag1s="<" & name & ">" ; // start tag
tag1e="</" & name & ">" ; // end tag

startN = Position ( xml ; tag1s ; 1 ; N ) ; // position of N-th start tag
endN = Position ( xml ; tag1e ; 1 ; 1 + $count1 ); // position of the (recursion run count)-th end tag
startNplus = Position ( xml ; tag1s ; 1 ; N + $count2 + 1);
$count1 = $count1+1;
$count2 = If( startNplus < endN ; $count2 + 1 ; $count2 ) ;

result=If ( PatternCount ( xml ; tag1e) <> PatternCount ( xml ; tag1s) //a bit of xml validity check
or
$count1 > PatternCount ( xml ; tag1e);
"error";
If ( startN < endN and endN < startNplus or startNplus = 0 ;
endN - 1;
xmlTagN.valuePosEnd (name ; xml ; N ) //recursion!
)
) ;
$count1 = "" ; //delete these 'local' variables after recursion. strangely they do behave global in custom function context
$count2 = "" ]; //if not deleted, they would still have the last value when the function is called the next time
result
)

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

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

    Prototype: xmlTagN.valuePosEnd( name; xml; N )
    Function Author: konrad (http://www.fmfunctions.com/mid/224)
    Last updated: 13 December 2009
    Version: 1.1

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

 

 

 

 

 

 

 

Top Tags

Text Parsing  (33)
List  (31)
Date  (28)
XML  (26)
Format  (23)
Sql  (22)
Dev  (20)
Debug  (17)
Interface  (15)
Layout  (15)
Text  (14)
Variables  (12)
Layout Objects  (11)
Filter  (11)
Design  (10)
Array  (7)