Function overview
Prototype
ExtractData (
XML; Attribute; Instance )
Parameters
XML
Attribute The node of the XML which you wish to return
Instance Which instance of the specified node to return
Description
Tags:
XML
Use this function to search for and return the specified instance of a field from any valid XML source.
Examples
Sample input
ExtractData ( "<xml>
<InvNum>123</InvNum>
<InvNum>456</InvNum>
<InvNum>789</InvNum>
</xml>" ; "InvNum" ; 2 )
Sample output
456
Function code
// ExtractData ( XML ; Attribute ; Instance )
// Created by Andy Knasinski, NRG Software
Let ( [
XML_Length = Length ( XML ) ;
Attribute_Length = Length ( Attribute ) ;
Get_Instance = If ( IsEmpty ( Instance ) ; 1 ; Instance )
];
Case(
IsEmpty ( XML ) or IsEmpty ( attribute ) or PatternCount ( xml ; "<" & attribute & ">" ) = 0 ; "" ;
Middle ( XML ; Position ( XML ; "<" & attribute & ">" ; 1 ; Get_Instance ) + attribute_length + 2 ;
xml_length - ( xml_length - Position ( XML ; "</" & attribute & ">" ; 1 ; Get_Instance ) ) - ( Position ( XML ; "<" & attribute & ">" ; 1 ; Get_Instance ) + Attribute_Length + 2 ) )
) )
// ===================================
/*
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/202
Prototype: ExtractData( XML; Attribute; Instance )
Function Author: Michael W. (http://www.fmfunctions.com/mid/154)
Last updated: 14 February 2009
Version: 1
*/
// ===================================
// ExtractData ( XML ; Attribute ; Instance )__LITBR__// Created by Andy Knasinski, NRG Software__LITBR____LITBR__Let ( [ __LITBR__XML_Length = Length ( XML ) ; __LITBR__Attribute_Length = Length ( Attribute ) ; __LITBR__Get_Instance = If ( IsEmpty ( Instance ) ; 1 ; Instance ) __LITBR__]; __LITBR__Case(__LITBR__IsEmpty ( XML ) or IsEmpty ( attribute ) or PatternCount ( xml ; "<" & attribute & ">" ) = 0 ; "" ;__LITBR__Middle ( XML ; Position ( XML ; "<" & attribute & ">" ; 1 ; Get_Instance ) + attribute_length + 2 ; __LITBR__xml_length - ( xml_length - Position ( XML ; "</" & attribute & ">" ; 1 ; Get_Instance ) ) - ( Position ( XML ; "<" & attribute & ">" ; 1 ; Get_Instance ) + Attribute_Length + 2 ) )__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/202__LITBR____LITBR__ Prototype: ExtractData( XML; Attribute; Instance )__LITBR__ Function Author: Michael W. (http://www.fmfunctions.com/mid/154)__LITBR__ Last updated: 14 February 2009__LITBR__ Version: 1__LITBR____LITBR__*/__LITBR__// ===================================