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  (66 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:

5 most recent comments | Show all 6 comments

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

Dosent work!

Try:
<SalesRankings>
<SalesRank>
<ProductCategoryId>music_display_on_website</ProductCategoryId>
<Rank>1981</Rank>
</SalesRank>
<SalesRank>
<ProductCategoryId>1033930</ProductCategoryId>
<Rank>50</Rank>
</SalesRank>
<SalesRank>
<ProductCategoryId>1033714</ProductCategoryId>
<Rank>90</Rank>
</SalesRank>
<SalesRank>
<ProductCategoryId>1033792</ProductCategoryId>
<Rank>172</Rank>
</SalesRank>
</SalesRankings>

with key SalesRank.
It will match on SalesRankings!!!

Jim, Newyork
April 06, 2016 9:29pm

Try this one:


Let ([

XML_Length = Length ( XML );
Attribute_Length = Length ( Attribute );

PosStartTag = If ( Position ( XML ; "<" & Attribute & " " ; 1 ; 1 ) > 0;
Position ( XML ; "<" & Attribute & " "; 1; Instance );
Position ( XML ; "<" & Attribute & ">"; 1; Instance ) );

TagName = If ( Position ( XML ; "<" & Attribute & " " ; 1 ; 1 ) > 0;
Middle ( XML ; PosStartTag ; Position ( XML ; ">" ; PosStartTag ; 1 ) +1 - PosStartTag );
"<" & Attribute & ">");

PosEndTag = Position ( XML ; "</" & Attribute & ">"; PosStartTag; 1 );

TheResult = Case(
IsEmpty ( XML ) or
IsEmpty ( Attribute ) or
(PosStartTag = 0 ); // Attribute not in XML at all
"";
Middle (XML; PosStartTag + Length ( TagName ); PosEndTag - (PosStartTag + Length ( TagName )))
)

];

TheResult

)

Jim, Newyork
April 06, 2016 11:51pm

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 1 + 3 =
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. CurrencyFormat ( Sum, CU ; DP ; BP ; ND )
  (Mon, Jun 27, 3:24am)
2. QuarterHrs ( Timestamp )
  (Mon, Jun 27, 2:52am)
3. QuarterHourRound ( Timestamp )
  (Mon, Jun 27, 1:18am)
4. DistributeExpression ( Expression ; Variable ; Values ; Separator )
  (Thu, Jun 23, 3:42pm)
5. TimestampOffset ( Time_Stamp ; Weeks ; Days ; Hours ; Minutes ; Second ; Plus_Minus )
  (Thu, Jun 23, 9:32am)
6. SplitValues ( InputString ; ListSeparator ; ChunkSize )
  (Tue, Jun 21, 3:27am)
7. SpellNumber ( Amt )
  (Thu, Jun 16, 11:08pm)
8. dispjahr (sorted;index)
  (Sat, Jun 04, 10:01pm)

RSS Feed of Custom Functions