Brian Dunning's FileMaker Custom Functions

GetFieldsAsXML ( theFields )

Convert a list of fields to XML data

  Average rating: 4.4 (33 votes) Log in to vote

Andy Knasinski   Andy Knasinski
NRG Software, LLC.
http://www.nrgsoft.com

Share on Facebook Share on Twitter

  Sample input:
GetFieldsAsXML ( FieldNames ( Get ( FileName ) ; Get ( LayoutName ) ) )
  Sample output:
nrg software, llc
andy knasinski
po box 341338


milwaukee
wi
53234
UNITED STATES

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

// Description:
// GetFieldsAsXML ( theFields )
// A recursive function that takes a list of field names
// and returns an XML string with the field values
// note that alphanumeric field names should be used in order to produce valid XML

 

Comments

Bruce Robertson   Bruce Robertson
Jan 20, 2012
Are the pipe and shift-space encodings correct? And what is their purpose?
 
Christoph Kaufmann   Christoph Kaufmann, CLK.ch
Oct 8, 2013
// modified to allow for empty fields (self closing tag <field/>)

If ( IsEmpty ( theFields );
theFields;

Let ( [
attribute = GetValue ( theFields ; 1 ) ;
xmlString = Substitute ( GetField (attribute) ;
[ "|";" " ] ; // pipe
[ " ";" " ] ; // shift-space
[ "&" ; "&amp;" ] ;
[ "<" ; "&lt;" ] ;
[ ">" ; "&gt;" ] ;
[ "\"" ; "&quot;" ] ;
[ "'" ; "&apos;" ]
)
] ; // End of the definitions

// Self closing tag if xmlString is empty:
If ( IsEmpty ( xmlString ) ; "<" & attribute & "/>"

; // else open and close tag
"<" & attribute & ">" // open tag
&
xmlString // content
&
"</" & attribute & ">" // close tag

) // Ende If

& // starting over with the next field

If ( ValueCount ( theFields ) > 1 ; "¶" ; "" ) &
GetFieldsAsXML (
RightValues ( theFields ; ValueCount ( theFields ) - 1 )
) // End If
) // End Let
) // End of the initial If
 

Log in to post comments.

 

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

Under construction. Email me your wish list for improvements.