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: 12 December 2009
Version: 1.1
*/
// ===================================
//sets value of a tag with given name, only when tag found in the top level of the given hierarchical xml structure__LITBR__//scans through the top level tags by recursion__LITBR____LITBR__Let([__LITBR____LITBR__value0 = TrimSpaceCR ( value ); //readability: remove leading and trailing " " or "¶"__LITBR__value0 = If(Left ( value0 ; 1 )="<";"¶ ")&value0; //readability: set in xml tags in given value__LITBR__value0 = Substitute ( value0; ">¶" ; ">¶ ");__LITBR____LITBR__t1 = "<"&name&">";__LITBR__t2 = "</"&name&">";__LITBR____LITBR__a = Position(xml ; "<" ; 1 ; 1 );__LITBR__b = Position(xml ; ">" ; 1 ; 1 );__LITBR__name0 = Middle ( xml ; a + 1 ; b - a - 1); //name of first tag in given xml__LITBR____LITBR__xmlR = xmlWithoutFirstTag ( xml ); // rest of xml after first tag__LITBR____LITBR__xml = If( PatternCount (xml ; t1 ) < 1 ;__LITBR__ xml & If( value<>""; "¶<" & name & ">" & value0 & "</" & name & ">" ) ; //add no empty tag__LITBR__ If( name0 = name; __LITBR__ If(value <>""; t1 & value0 & t2 & "¶") & xmlR ; //empty value deletes tag__LITBR__ xmlFirstTag ( xml ) & "¶" & xmlSetTop ( name ; value ; xmlR ) //recursion!__LITBR__ )__LITBR__ ) ];__LITBR____LITBR__Substitute ( xml; "><"; ">¶<") //readability__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/243__LITBR____LITBR__ Prototype: xmlSetTop( name; value; xml )__LITBR__ Function Author: konrad (http://www.fmfunctions.com/mid/224)__LITBR__ Last updated: 12 December 2009__LITBR__ Version: 1.1__LITBR____LITBR__*/__LITBR__// ===================================
Login or register to comment
Create a new account with fmcustomfunctions.com or login to post a comment.