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
*/
// ===================================
//search position of the corresponding end tag for the N-th start tag with the given name__LITBR__//result ist the position of the last character bevor the searched end tag__LITBR____LITBR__Let([__LITBR____LITBR__tag1s="<" & name & ">" ; // start tag__LITBR__tag1e="</" & name & ">" ; // end tag__LITBR____LITBR__startN = Position ( xml ; tag1s ; 1 ; N ) ; // position of N-th start tag__LITBR__endN = Position ( xml ; tag1e ; 1 ; 1 + $count1 ); // position of the (recursion run count)-th end tag__LITBR__startNplus = Position ( xml ; tag1s ; 1 ; N + $count2 + 1); __LITBR__$count1 = $count1+1;__LITBR__$count2 = If( startNplus < endN ; $count2 + 1 ; $count2 ) ;__LITBR____LITBR__result=If ( PatternCount ( xml ; tag1e) <> PatternCount ( xml ; tag1s) //a bit of xml validity check__LITBR__ or __LITBR__ $count1 > PatternCount ( xml ; tag1e); __LITBR__ "error";__LITBR__ If ( startN < endN and endN < startNplus or startNplus = 0 ;__LITBR__ endN - 1; __LITBR__ xmlTagN.valuePosEnd (name ; xml ; N ) //recursion!__LITBR__ )__LITBR__ ) ;__LITBR__$count1 = "" ; //delete these 'local' variables after recursion. strangely they do behave global in custom function context__LITBR__$count2 = "" ]; //if not deleted, they would still have the last value when the function is called the next time__LITBR__result__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/239__LITBR____LITBR__ Prototype: xmlTagN.valuePosEnd( name; xml; N )__LITBR__ Function Author: konrad (http://www.fmfunctions.com/mid/224)__LITBR__ Last updated: 13 December 2009__LITBR__ Version: 1.1__LITBR____LITBR__*/__LITBR__// ===================================