Brian Dunning's FileMaker Custom Functions

ExtractXMLAttributeList__cf ( _xml ; _attribute ; _instance )

Extracts a list of values that are contained within the XML attribute tag

  Average rating: 4.5 (31 votes) Log in to vote

Steve Hearn   Steve Hearn
CoreSolutions Software Inc
http://coresolutions.ca

Share on Facebook Share on Twitter

  Sample input:
ExtractXMLAttributeList__cf (
PhillipSusanJohnHeather
David ; "tag1" ; "" )
  Sample output:
Phillip
John
David

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

-Purpose-
Recursive function to extract a list of values that are contained within the XML attribute tag.

-Parameters-
_xml - the source containing the XML data
_attribute - the XML tag to search for
_instance - the occurrance number to extract up to OR leave blank to extract a list (a value of 2 will produce a list of the first 2 occurrences)

-Important Notes-
Credit to Andy Knasinski, NRG Software (http://www.nrgsoft.com/) for his function ExtractData ( XML ; Attribute ; Instance ) on which my function is based.

 

Comments

Bruce Robertson   Bruce Robertson
Nov 19, 2010
Can't see any advantage here and it seems confusing. If you enter 2 for the instance you do not get instance 2, you get the first two instances? When do you ever get what you ask for? Seems like you should be processing instances as a list.
 
comment   comment, VR
Nov 23, 2010
A semantic note:

The use of the word "attribute" is incorrect and misleading. In the given example, "tag1" is the name of an ELEMENT. An element can have attributes, for example:

<tag1 role="husband">Phillip</tag1>

The string "Phillip" is the TEXT CONTENT of the "tag1" element, while "husband" is the value of the "role" attribute.
 
Steve Hearn   Steve Hearn, London ON
Nov 24, 2010
Thanks for the feedback Bruce.

I use this CF to obtain a list of all the field names, for instance, that I copy from a layout. I use ClipMgr to expose the XML then paste it in a little utility file with this CF and key in the tag I want and leave the instance blank. It's true that you get a list up to the instance you specify; if you want just the instance I guess you'd want to use Andy Knasinski's function, on which this one is based.
 
Jim   Jim, Newyork
Apr 6, 2016
Dosent work either!
Dosent any ever check their 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!!!
 

Log in to post comments.

 

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

Under construction. Email me your wish list for improvements.