GetXMLNode ( )

Function stats

Average user rating
5.0000
154
203
9999
Support
FileMaker 7.0 +
Date posted
14 February 2009
Last updated
16 February 2009
Version
Recursive function
No

Author Info
 Michael W.

3 functions

Average Rating 5.0

author_avatar



 

Function overview

Prototype

GetXMLNode  ( XML;   XPath )


Parameters

XML  The xml to be traversed using the xpath


XPath  The path down the XML tree formatted as /nodeName[instance]/nodeName[instance]


Description

Tags:  XML XPath  

Navigate XML tree and return results using XPath type functionality.

Parameter Description
XML - vanilla xml imput without attributes
XPath - basic XPath like syntax consiting of a series of xml nodes formatted as follows:
/nodeName[instanceNumber]


Requires ExtractData ( XML ; Attribute ; Instance ) by Andy Knasinski of NRG Software which can be found at http://www.briandunning.com/cf/1

Thanks to Andy for the great base function!

This function is not recursive. It simply creates multiple nested instances of GetXMLData in a calculation string and then evaluates it to get the data.

*************
EXAMPLE USE
*************
XMLfield is set to:
<class>
<teacher>
<name>Kelly</name>
</teacher>
<students>
<student>
<name>Bill</name>
<age>15</age>
</student>
<student>
<name>Sue</name>
<age>16</age>
</student>
</students>
<class>

GetXMLNode ( XMLfield ; "/class[1]/teacher[1]/name[1]" ) & "¶" &
GetXMLNode ( XMLfield ; "/class[1]/students[1]/student[2]/age[1]" ) & "¶" &
GetXMLNode ( XMLfield ; "/class[1]/students[1]/student[1]" )

Will produce the following:
Kelly
16
<name>Bill</name><age>15</age>

Examples

Sample input

XMLfield is set to:
<class><student>Bill</student><student>Sue</student><class>
GetXMLNode ( XMLfield ; "/class[1]/student[1]" ) & "¶" &
GetXMLNode ( XMLfield ; "/class[1]/student[2]" )


Sample output

Bill
Sue

 

Function code

// GetXMLNode ( XML ; XPath )
// Requires ExtractData ( XML ; Attribute ; Instance )
// ExtractData can be found at http://www.briandunning.com/cf/1
// Thanks to Andy Knasinski of NRG Software for the great base function!

// *** Parameter Description ***
// XML - vanilla xml imput without attributes
// XPath - basic XPath like syntax consiting of
// a series of xml nodes formatted as follows:
// /nodeName[instanceNumber]

Evaluate ( Substitute ( Filter ( XPath ; "/" ) ; "/" ; "ExtractData ( " ) & "\"" & XML & "\"" & Substitute ( XPath ; [ "/" ; ";\"" ] ; [ "[" ; "\";" ] ; [ "]" ; ")" ] ) )


/****************************************************************
Nonrecursive, this function simply creates multiple nested instances of GetXMLData in a calculation string and then evaluates it to get the data.

************************* EXAMPLE USE ***************************
XMLfield is set to:
<class>
<teacher>
<name>Kelly</name>
</teacher>
<students>
<student>
<name>Bill</name>
<age>15</age>
</student>
<student>
<name>Sue</name>
<age>16</age>
</student>
</students>
<class>

GetXMLNode ( XMLfield ; "/class[1]/teacher[1]/name[1]" ) & "¶" &
GetXMLNode ( XMLfield ; "/class[1]/students[1]/student[2]/age[1]" ) & "¶" &
GetXMLNode ( XMLfield ; "/class[1]/students[1]/student[1]" )

Will produce the following:
Kelly
16
<name>Bill</name><age>15</age>

****************************************************************
****************************************************************/

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

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

    Prototype: GetXMLNode( XML; XPath )
    Function Author: Michael W. (http://www.fmfunctions.com/mid/154)
    Last updated: 16 February 2009
    Version: 1.1

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

 

Comments

Fabrice
14 February 2009



Wow ! this is awsome ! thanks for sharing !
(Edited by Fabrice on 14/02/09 )
  General comment