xmlGet ( )

Function stats

Average user rating
5.0000
37
110
9999
Support
FileMaker 7.0 +
Date posted
05 December 2008
Last updated
22 April 2010
Version
Recursive function
No

Author Info
 Fabrice

77 functions

Average Rating 4.4

author_avatar



 

Function overview

Prototype

xmlGet  ( _xml;   _tag )


Parameters

_xml  


_tag  


Description

Tags:  XML  

extracts a value from an xml tag.
If the value begins with "=" (equal), then the result is evaluated.

_xml will be parsed. This means a substract of 'XML' like code can be passed to this function.

To evaluate an expression in a xml tag rather than a plain text, when xmlGet is evaluated, it must begin with "=".
e.g :
"3+4" --> "3+4"
"=3+4" --> "7"

Examples

Sample input

xmlGet ( "<firstname>John</firstname><surname>Smith</surname>" ; "surname" )


Sample output

Smith

 

Function code

/*
xmlGet ( _xml ; _tag )

by Fabrice Nordmann
http://www.1-more-thing.com

v4, Feb 2008

generic xml tag extractor
---
v4 Feb 2008. Doesn't handle LayoutProperties anymore (LayoutProperties must now be passed in _xml parameter)
v3 Dec 2007. Renamed xmlGet (was PropertyValue)
v2.1 Aug 2007. Forces evaluation of ¶ by substitution de-substitution
v2 May 2007
v1 Renamed PropertyValue (was called ObjValue), and was working in a completely different way
---

READ ME (IMPORTANT)
_xml will be parsed. This means a substract of 'XML' like code can be passed to this function.

to evaluate an expression in a xml tag rather than a plain text, when xmlGet is evaluated, it must begin with "=".
e.g :
"3+4" --> "3+4"
"=3+4" --> "7"

-------------------------------------------------
*/
Let ([
_tagLength = Length ( _tag )
; _tagStart = Position ( _xml ; "<" & _tag & ">" ; 1 ; 1 ) + _tagLength + 2
; _tagEnd = Position ( _xml ; "</" & _tag & ">" ; _tagStart ; 1 )
; _tag = Substitute ( Middle ( _xml ; _tagStart ; _tagEnd - _tagStart ) ; ¶ ; "ïMπRößablÊsTrìNg" )
]
;
Substitute (
Case ( Left ( _tag ; 1 ) = "=" ;
Evaluate ( Replace ( _tag ; 1 ; 1 ; "" ))
; Evaluate ( Quote ( _tag ))
)
; "ïMπRößablÊsTrìNg" ; ¶ )
)

// ===================================
/*

    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/110

    Prototype: xmlGet( _xml; _tag )
    Function Author: Fabrice (http://www.fmfunctions.com/mid/37)
    Last updated: 22 April 2010
    Version: 1.2

*/
// ===================================

 

Comments

Andries Heylen
28 April 2016



I don't understand why you use the "Evaluate" part when there is no "=" sign... just returning the tag seems sufficient to me ;)
  General comment
Andries Heylen
28 April 2016



I don't understand why you use the "Evaluate" part when there is no "=" sign... just returning the tag seems sufficient to me ;)
  General comment
Fabrice
28 April 2016



Andries, if you want to ask me something, I'm in the office next to yours. Do not hesitate :)
The thing is… I don't remember either, and it's been on my list for long. Quite sure it was necessary in some situations, but I don't remember. It's unfortunate because we're losing rich text attributes…
  General comment