Function overview
Prototype
xmlGetWhere (
_xml; _tag; _tagWhere; _value )
Parameters
_xml an xml string
_tag the tag (node) to extract
_tagWhere the nested tag (node) where the value is required
_value
Description
Tags:
xml Text Parsing Debug
In an xml structure, extracts the nodes ( _tag ) where a nested tag matches a value.
Examples
Sample input
if _xml is:
<contact><ID>67</ID><Name>Wesson</Name></contact>
<contact><ID>124</ID><Name>Smith</Name></contact>
<contact><ID>780</ID><Name>Wesson</Name></contact>
Example :
// The contact tag(s) that where a Name tag equals Wesson
xmlGetWhere ( _xml ; "contact" ; "Name" ; "Wesson" )
Sample output
<contact><ID>67</ID><Name>Wesson</Name></contact>
<contact><ID>780</ID><Name>Wesson</Name></contact>
Function code
/*
xmlGetWhere ( _xml ; _tag ; _tagWhere ; _value )
by Fabrice Nordmann
v.2.2 Jul 2009
- removed empty values
v.2.1 Jan 2009
- even faster. Ready for Sokoban 3D ;-)
v.2.0 Jan 2009
- re-written using CustomList (not recursive), so it shouldn't smoke intel CPUs anymore :)
v.1.0 Dec 2008
In an xml structure, extracts the nodes ( _tag ) where a nested tag matches a value.
Requires :
CustomList () : http://www.fmfunctions.com/fname/customlist
Parameters:
_xml : an xml string
_tag : the tag (node) to extract
_tagWhere : the nested tag (node) where the value is required
_value : what needs to be found in _tagWhere for _tag to be extracted
Example:
if _xml is:
<contact><ID>67</ID><Name>Wesson</Name></contact>
<contact><ID>124</ID><Name>Smith</Name></contact>
<contact><ID>780</ID><Name>Wesson</Name></contact>
------------------------
// The contact tag(s) that where a Name tag equals Wesson
xmlGetWhere ( _xml ; "contact" ; "Name" ; "Wesson" ) =
"<contact><ID>67</ID><Name>Wesson</Name></contact>
<contact><ID>780</ID><Name>Wesson</Name></contact>"
------------------------
*/
Let ([
$cf_xmlw_value = Substitute ( _value ; ¶ ; "#CR#" )
; $tagWhere = _tagwhere
; $cf_tagWhereWdata = "<" & $tagwhere & ">" & $cf_xmlw_value & "</" & $tagwhere & ">"
; $cf_matchString = "#M#A#T#C#H#"
; $cf_xmlw_xml = Substitute ( _xml ; [ "¶</" ; "#CLOSETAG#" ] ; [ "¶<" ; "<" ] ; [ "¶<" ; "<" ] ; [ "¶<" ; "<" ] ; [ "¶<" ; "<" ] ; [ "¶<" ; "<" ] ; [ "¶<" ; "<" ] ; [ "¶<" ; "<" ] ; [ "¶<" ; "<" ] ; [ "¶<" ; "<" ] ; [ "¶<" ; "<" ] ; [ "¶<" ; "<" ] ; [ "¶<" ; "<" ] ; [ "¶<" ; "<" ] ; [ "¶<" ; "<" ] ; ["#CLOSETAG#" ; "¶</" ] ; [ ¶ ; "#CR#" ] ; [ "<" & _tag ; "¶<" & _tag ] ; [ "¶</" & _tag & ">" ; "</" & _tag ] ; [ $cf_tagWhereWdata ; $cf_matchString ] )
];
Substitute ( CustomList ( 1 ; ValueCount ( $cf_xmlw_xml ) ; "let ([ $cf_xmlw_v = getvalue ( $cf_xmlw_xml ; [n] ) ]; case ( patterncount ( $cf_xmlw_v ; $cf_matchString ) ; $cf_xmlw_v ))" ) ; [ $cf_matchString ; $cf_tagWhereWdata ] ; [ "#CR#" ; ¶ ] )
)
// ===================================
/*
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/155
Prototype: xmlGetWhere( _xml; _tag; _tagWhere; _value )
Function Author: Fabrice (http://www.fmfunctions.com/mid/37)
Last updated: 28 July 2009
Version: 2.6
*/
// ===================================
/*__LITBR__xmlGetWhere ( _xml ; _tag ; _tagWhere ; _value )__LITBR____LITBR__by Fabrice Nordmann__LITBR____LITBR____LITBR__v.2.2 Jul 2009__LITBR__ - removed empty values__LITBR__v.2.1 Jan 2009__LITBR__ - even faster. Ready for Sokoban 3D ;-)__LITBR__v.2.0 Jan 2009__LITBR__ - re-written using CustomList (not recursive), so it shouldn't smoke intel CPUs anymore :)__LITBR__v.1.0 Dec 2008__LITBR____LITBR____LITBR__In an xml structure, extracts the nodes ( _tag ) where a nested tag matches a value.__LITBR____LITBR____LITBR__Requires :__LITBR__CustomList () : http://www.fmfunctions.com/fname/customlist __LITBR____LITBR____LITBR__Parameters:__LITBR___xml : an xml string__LITBR___tag : the tag (node) to extract__LITBR___tagWhere : the nested tag (node) where the value is required__LITBR___value : what needs to be found in _tagWhere for _tag to be extracted__LITBR____LITBR____LITBR__Example:__LITBR__if _xml is:__LITBR__<contact><ID>67</ID><Name>Wesson</Name></contact>__LITBR__<contact><ID>124</ID><Name>Smith</Name></contact>__LITBR__<contact><ID>780</ID><Name>Wesson</Name></contact>__LITBR____LITBR__------------------------__LITBR____LITBR__// The contact tag(s) that where a Name tag equals Wesson__LITBR____LITBR__xmlGetWhere ( _xml ; "contact" ; "Name" ; "Wesson" ) =__LITBR__"<contact><ID>67</ID><Name>Wesson</Name></contact>__LITBR__<contact><ID>780</ID><Name>Wesson</Name></contact>"__LITBR____LITBR__------------------------__LITBR__*/__LITBR____LITBR__Let ([__LITBR__ $cf_xmlw_value = Substitute ( _value ; ¶ ; "#CR#" )__LITBR__; $tagWhere = _tagwhere__LITBR__; $cf_tagWhereWdata = "<" & $tagwhere & ">" & $cf_xmlw_value & "</" & $tagwhere & ">"__LITBR__; $cf_matchString = "#M#A#T#C#H#"__LITBR__; $cf_xmlw_xml = Substitute ( _xml ; [ "¶</" ; "#CLOSETAG#" ] ; [ "¶<" ; "<" ] ; [ "¶<" ; "<" ] ; [ "¶<" ; "<" ] ; [ "¶<" ; "<" ] ; [ "¶<" ; "<" ] ; [ "¶<" ; "<" ] ; [ "¶<" ; "<" ] ; [ "¶<" ; "<" ] ; [ "¶<" ; "<" ] ; [ "¶<" ; "<" ] ; [ "¶<" ; "<" ] ; [ "¶<" ; "<" ] ; [ "¶<" ; "<" ] ; [ "¶<" ; "<" ] ; ["#CLOSETAG#" ; "¶</" ] ; [ ¶ ; "#CR#" ] ; [ "<" & _tag ; "¶<" & _tag ] ; [ "¶</" & _tag & ">" ; "</" & _tag ] ; [ $cf_tagWhereWdata ; $cf_matchString ] )__LITBR__];__LITBR__Substitute ( CustomList ( 1 ; ValueCount ( $cf_xmlw_xml ) ; "let ([ $cf_xmlw_v = getvalue ( $cf_xmlw_xml ; [n] ) ]; case ( patterncount ( $cf_xmlw_v ; $cf_matchString ) ; $cf_xmlw_v ))" ) ; [ $cf_matchString ; $cf_tagWhereWdata ] ; [ "#CR#" ; ¶ ] )__LITBR__)__LITBR____LITBR____LITBR____LITBR__// ===================================__LITBR__/*__LITBR____LITBR__ This function is published on FileMaker Custom Functions__LITBR__ to check for updates and provide feedback and bug reports__LITBR__ please visit http://www.fmfunctions.com/fid/155__LITBR____LITBR__ Prototype: xmlGetWhere( _xml; _tag; _tagWhere; _value )__LITBR__ Function Author: Fabrice (http://www.fmfunctions.com/mid/37)__LITBR__ Last updated: 28 July 2009__LITBR__ Version: 2.6__LITBR____LITBR__*/__LITBR__// ===================================
Login or register to comment
Create a new account with fmcustomfunctions.com or login to post a comment.
Comments
20 December 2008
13 February 2009