Dynamically eveluating the IsXmlElem function

I was having problems dynamically evaluating with the IsXmlElem function:

#IsXmlElem(xml.abc.def)#

worked fine, but:

<cfset a = "xml.abc.def">
#IsXmlElem(a)#

didn't. To make this work you need to:

<cfset a = "xml.abc.def">
#Evaluate("IsXmlElem(#a#)")#

Notes:

* The setting of the a variable can be dynamic. This is great if you have a list of elements and are looping over them to check for their existisnce.

* This also works of IsXmlNode and IsXmlAttribute.

Comments
Jeff Houser's Gravatar Ken,

In the first example you are referencing a variable that points to an XML document; in the second you are referencing a variable that points to a string value. As such, the functions are working as I would have expected.

This probably won't work:

#IsXmlElem("xml.abc.def")#

because you're referencing a string, which is not an XML Element. But, this will:

<cfset a = xml.abc.def>
#IsXmlElem(a)#

Because you are referencing an xml object (not a string version of its name).

If you're in a situation where you must be using a string, then evaluate is definitely the way to go.

Out of curiosity, can you quantify this with a more detailed example?
# Posted By Jeff Houser | 8/14/06 6:28 PM