xmlNode ( )

+ Edit this function

Function stats

Average user rating
231
9999
Support
FileMaker 7.0 +
Date posted
10 July 2009
Version
1
Recursive function
No

Author Info
 

0 functions

Average Rating None

author_avatar



 

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

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

 

 

 

 


Login or register to comment

Create a new account with fmcustomfunctions.com or login to post a comment.

 

 

 

Top Tags

Text Parsing  (31)
List  (20)
XML  (20)
Date  (19)
Format  (18)
Debug  (12)
Dev  (11)
Variables  (11)
Layout  (11)
Interface  (10)
Text  (10)
Filter  (10)
ValueIterator  (6)
Layout Objects  (6)
Uuid  (6)
HTML  (6)