Function overview
Prototype
xmlNode (
name; required; attributes; contents )
Parameters
name Name of the node
required Should this node be created regardless of whether it has contents. If required & contents is empty it will create an empty node
attributes Space separated XML attributes in the form attributename="something". As per the XML standard
contents What should appear
Description
Tags:
XML
Create an XML node. It doesn't cater for invalid XML characters in the name, attributes or contents as yet but might add it soon.
The reason you might use the required parameter is if you are referencing a field for contents & you don't need the node to exist if the field is empty.
There might also be scope for creating an xmlAttribute( name ; value ) Custom Function as well but thought it just clutters it for the moment... it might look something like this:
name & "=\"" & value & "\""
Usage would be something like
list( xmlAttribute( "validate" ; "true" ) ; xmlAttribute( "keyword" ; "please" ) )
Examples
Sample input
// No database fields example
xmlNode( "basket" ; 1 ; "validate=\"true\"" ;
xmlNode( "item" ; 1 ; "validate=\"true\"" ; "shoe" )
xmlNode( "item" ; 0 ; "validate=\"true\"" ; "" )
xmlNode( "item" ; 1 ; "validate=\"true\"" ; "" )
xmlNode( "jacket" ; 1 ; "validate=\"true\"" ; "jacket" )
)
Sample output
// Database fields example where you are in the BASKET table listing related records from the ITEMS table.
xmlNode( "basket" ; 1 ; "validate=\"true\"" ;
list( basket_ITEMS::xmlNodeCalc )
)
/* For this example table ITEMS contains fields "xmlNodeCalc"
and "item_name". "xmlNodeCalc" would evaluate to the following:
xmlNode( "item" ; 1 ; "validate=\"true\"" ; item_name )
*/
Function code
If( required or ( not ( IsEmpty( attributes ) and IsEmpty( contents ) ) ) ;
Substitute(
¶ & "<" & name & If( not IsEmpty( attributes ) ; " " ) & attributes &
If( IsEmpty( contents ) ;
" />" ;
">" & contents & If( Position( contents ; "<" ; 1 ; 1 ) > 0 ; ¶ ) & "</" & name & ">"
) ; ¶ ; "¶ " ) )
// ===================================
/*
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/231
Prototype: xmlNode( name; required; attributes; contents )
Function Author: (http://www.fmfunctions.com/mid/)
Last updated: 10 July 2009
Version: 1
*/
// ===================================
If( required or ( not ( IsEmpty( attributes ) and IsEmpty( contents ) ) ) ;__LITBR____LITBR__Substitute(__LITBR____LITBR__¶ & "<" & name & If( not IsEmpty( attributes ) ; " " ) & attributes &__LITBR____LITBR__If( IsEmpty( contents ) ;__LITBR____LITBR__" />" ;__LITBR____LITBR__">" & contents & If( Position( contents ; "<" ; 1 ; 1 ) > 0 ; ¶ ) & "</" & name & ">"__LITBR____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/231__LITBR____LITBR__ Prototype: xmlNode( name; required; attributes; contents )__LITBR__ Function Author: (http://www.fmfunctions.com/mid/)__LITBR__ Last updated: 10 July 2009__LITBR__ Version: 1__LITBR____LITBR__*/__LITBR__// ===================================
Login or register to comment
Create a new account with fmcustomfunctions.com or login to post a comment.