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
*/
// ===================================
// GetXMLNode ( XML ; XPath )__LITBR__// Requires ExtractData ( XML ; Attribute ; Instance ) __LITBR__// ExtractData can be found at http://www.briandunning.com/cf/1 __LITBR__// Thanks to Andy Knasinski of NRG Software for the great base function!__LITBR____LITBR__// *** Parameter Description ***__LITBR__// XML - vanilla xml imput without attributes__LITBR__// XPath - basic XPath like syntax consiting of__LITBR__// a series of xml nodes formatted as follows:__LITBR__// /nodeName[instanceNumber] __LITBR____LITBR__Evaluate ( Substitute ( Filter ( XPath ; "/" ) ; "/" ; "ExtractData ( " ) & "\"" & XML & "\"" & Substitute ( XPath ; [ "/" ; ";\"" ] ; [ "[" ; "\";" ] ; [ "]" ; ")" ] ) )__LITBR____LITBR____LITBR__/****************************************************************__LITBR__Nonrecursive, this function simply creates multiple nested instances of GetXMLData in a calculation string and then evaluates it to get the data.__LITBR____LITBR__************************* EXAMPLE USE ***************************__LITBR__XMLfield is set to:__LITBR__<class>__LITBR__ <teacher>__LITBR__ <name>Kelly</name>__LITBR__ </teacher>__LITBR__ <students>__LITBR__ <student>__LITBR__ <name>Bill</name>__LITBR__ <age>15</age>__LITBR__ </student>__LITBR__ <student>__LITBR__ <name>Sue</name>__LITBR__ <age>16</age>__LITBR__ </student>__LITBR__ </students>__LITBR__<class>__LITBR____LITBR__GetXMLNode ( XMLfield ; "/class[1]/teacher[1]/name[1]" ) & "¶" & __LITBR__GetXMLNode ( XMLfield ; "/class[1]/students[1]/student[2]/age[1]" ) & "¶" & __LITBR__GetXMLNode ( XMLfield ; "/class[1]/students[1]/student[1]" )__LITBR____LITBR__Will produce the following:__LITBR__Kelly__LITBR__16__LITBR__<name>Bill</name><age>15</age>__LITBR____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/203__LITBR____LITBR__ Prototype: GetXMLNode( XML; XPath )__LITBR__ Function Author: Michael W. (http://www.fmfunctions.com/mid/154)__LITBR__ Last updated: 16 February 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.
Comments
14 February 2009
(Edited by Fabrice on 14/02/09 )