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  (51 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 4 + 5 =
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. IsLastDayMonth ( TheDate )
  (Wed, Mar 04, 2:12am)
2. HaversineDistance ( latx ; lony ; laty ; lony ; units )
  (Tue, Mar 03, 11:43am)
3. removeFirstAddPrefixSuffixToList ( theList ; prefix ; suffix )
  (Thu, Feb 26, 3:38am)
4. ETA(StartTime;Current;OfTotal)
  (Tue, Feb 24, 7:44pm)
5. MkDir {FolderName; MyPath}
  (Tue, Feb 24, 6:20am)
6. EngNotation ( number; digits )
  (Thu, Feb 19, 5:19pm)
7. GetXmlContent ( theXml ; theNodeName ; theInstanceNumber )
  (Mon, Feb 16, 4:17pm)
8. InterpretDateFromText ( dateText ; noResult )
  (Sun, Feb 15, 12:49pm)

RSS Feed of Custom Functions