xmlSetTop ( )

Function stats

Average user rating
224
243
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

xmlSetTop  ( name;   value;   xml )


Parameters

name  


value  


xml  


Description

Tags:  xml  

store multible named values in one field or variable!
usefull to pass over multible values as a scriptparameter

sets value of a tag with given name, only when tag found in the top level of the given hierarchical xml structure
scans through the top level tags by recursion

if named tag is already in the xml, the value is replaced
if named tag is new, it will be included
if the value is "", the named tag will be deleted from xml

Examples

Sample input

xmlSetTop ( "contact" ;
"<ID>456</ID>
<Lastname>Paul</Lastname>" ;
"<contact>
<ID>2354</ID>
<Lastname>Frank</Lastname>
</contact>
<letter>
<ID>234</ID>
</letter>"


Sample output

<contact>
<ID>456</ID>
<Lastname>Paul</Lastname>
</contact>
<letter>
<ID>234</ID>
</letter>

 

Function code

//sets value of a tag with given name, only when tag found in the top level of the given hierarchical xml structure
//scans through the top level tags by recursion

Let([

value0 = TrimSpaceCR ( value ); //readability: remove leading and trailing " " or "¶"
value0 = If(Left ( value0 ; 1 )="<";"¶ ")&value0; //readability: set in xml tags in given value
value0 = Substitute ( value0; ">¶" ; ">¶ ");

t1 = "<"&name&">";
t2 = "</"&name&">";

a = Position(xml ; "<" ; 1 ; 1 );
b = Position(xml ; ">" ; 1 ; 1 );
name0 = Middle ( xml ; a + 1 ; b - a - 1); //name of first tag in given xml

xmlR = xmlWithoutFirstTag ( xml ); // rest of xml after first tag

xml = If( PatternCount (xml ; t1 ) < 1 ;
xml & If( value<>""; "¶<" & name & ">" & value0 & "</" & name & ">" ) ; //add no empty tag
If( name0 = name;
If(value <>""; t1 & value0 & t2 & "¶") & xmlR ; //empty value deletes tag
xmlFirstTag ( xml ) & "¶" & xmlSetTop ( name ; value ; xmlR ) //recursion!
)
) ];

Substitute ( xml; "><"; ">¶<") //readability
)

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

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

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

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