Software Venture Consulting
ToMarket

FileMaker Pro downloads & Resources
FileMaker Custom Functions
FileMaker Web Viewer Examples
FileMaker Pro & Lasso Consulting
Training
FileMaker Books
FileMaker Articles
FileMaker Error Reference

Free Web Tools
Free FileMaker Tools

Personal Pages
Videos
Adventures
Links

Shopping Cart
Shopping Cart

Search:

Free Newsletter
Signup


Contact


Privacy Policy



FileMaker is a registered trademark of FileMaker, Inc. in the U.S. and other countries.

 

 FileMaker Pro Custom Functions

List  |  Show Random  |  Upload  |  Add This to Your Site

ExtractData ( XML ; Attribute ; Instance )

Rate this function:  

RatingRatingRatingRatingRating
  Average rating: 3.6  (43 votes)
  Discuss this Custom Function

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

Extract specific data out of XML formatted text without using FileMaker's built-in XML functionality.

Sample Input:
ExtractData ( "<xml>
<InvNum>123</InvNum>
<InvNum>456</InvNum>
<InvNum>789</InvNum>
</xml>" ; "InvNum" ; 2 )
Sample Output:
456


 Then copy & paste into FileMaker Advanced's Edit Custom Function window.

Click here to copy To Clip Manager if you have myFMbutler's Clip Manager installed

Description:

Use this function to search for and return the specified instance of a field from any valid XML source.

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

This is my Custom Function and I want to edit it

Discuss:

Very clever
I was looking for a way to import XML data created from a web application(ASP.net 2.0 technology)
to a FileMaker Pro 8.0 database table, but your code up there caught my atttention for its logic.
God Bless

gus ohouo, Atlanta, GA
January 08, 2009 12:34pm

Andy,

Nice function - very simple - gets the job done!

Charlie Bailey, Northampton MA
January 10, 2011 2:32pm

Here's a modified version that should handle attributes within the tags (where "tags" are what Andy called "attributes"). In other words, if your XML looks like this:

<xml>
<InvNum id="first" >123</InvNum>
<InvNum id="second" >456</InvNum>
<InvNum id="third" >789</InvNum>
</xml>

This should still get the value "456" if called as ExtracData( XML; "InvNum"; 2 )

Note that it still won't handle cases where attributes include ">" or where data looks like XML tags. No CDATA handling.

// ExtractData ( XML ; Attribute ; Instance )
// version 1.1, Daniel A. Shockley
// Based on code by Andy Knasinski, NRG Software, http://www.nrgsoft.com/

Let ( [
XML_Length = Length ( XML )
; Attribute_Length = Length ( Attribute )
; Get_Instance = If ( IsEmpty ( Instance ) ; 1 ; Instance )
; posOpenTagStart = Position ( XML ; "<" & Attribute; 1; Get_Instance )
; posNextOpen = Position ( XML ; "<"; posOpenTagStart + 1; 1 )
; posOpenTagFinish = Position ( XML ; ">"; posOpenTagStart; 1 )
; posCloseTagStart = Position( XML; "</" & Attribute & ">"; posOpenTagFinish; 1 )
];


Case(
IsEmpty ( XML ) or IsEmpty ( Attribute )
or ( posOpenTagStart = 0 ) // Attribute not in XML at all
or ( posNextOpen>0 and posOpenTagFinish> posNextOpen ) // Attribute seems to start, but another tag starts before opening tag brackets close
; ""
;
Middle (
XML
; posOpenTagFinish + 1
; posCloseTagStart - posOpenTagFinish - 1
)
)

)

Daniel A. Shockley, New York, NY
May 10, 2011 2:28pm

Really helpful.

Anannyaap, India
April 14, 2014 2:50am

Make a comment about this Custom Function (please try to keep it brief & to the point). Anyone can post:

Your Name:
City/Location:
Comment:
characters left. If you paste in more than 1500 characters, it will be truncated. Discuss the function - advertisements and other useless posts will be deleted.
Answer 9 + 8 =
Search for Custom Functions:

Custom Functions Widget
Download the Custom Function Dashboard Widget for OS X
Keep all the latest Custom Functions right at your fingertips!

Newest Custom Functions:

1. ExtractingEmails ( TheText ; Separator )
  (Mon, Nov 24, 10:34am)
2. DateArrayCurrent(array;i)
  (Wed, Nov 12, 9:11am)
3. OrdinalSuffix ( value )
  (Tue, Nov 04, 10:10am)
4. StateAbbrev ( state )
  (Tue, Oct 28, 10:10pm)
5. CorrectContext ( getFieldName_ )
  (Tue, Oct 28, 12:59pm)
6. ApplyFunction( function; value )
  (Sun, Oct 26, 5:40pm)
7. cf_postANC ( title ; subtitle ; Message ; sound )
  (Fri, Oct 24, 8:56am)
8. AS_File_Open ( myPath ; myOptions )
  (Sat, Oct 18, 8:04pm)

RSS Feed of Custom Functions