ExtractData ( )

Function stats

Average user rating
5.0000
154
202
9999
Support
FileMaker 7.0 +
Date posted
14 February 2009
Version
1
Recursive function
No

Author Info
 Michael W.

3 functions

Average Rating 5.0

author_avatar



 

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

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