GetXmlAttribute(node, attribute[, default])
Last updated December 23, 2002
Version: 1 | Requires: CF6 | Library: DataManipulationLib
Description:
This tag will allow you to retrieve an XML attribute from an XML node. Furthermore, if you are in the habit of needing default values in case the attribute's value is empty or the attribute does not exist, you can specify that as well.
Return Values:
Returns a string.
Example:
<cfxml variable="XmlScheme">
<cfoutput>
<xmlscheme>
<xmlnode oneatt="1" threeatt="3">Some Content</xmlnode>
</xmlscheme>
</cfoutput>
</cfxml>
<cfdump var="#XmlScheme#">
<cfscript>
oneVar=GetXmlAttribute(XmlScheme.XmlRoot.XmlChildren[1],"oneatt");
WriteOutput(oneVar);
twoVar=GetXmlAttribute(XmlScheme.XmlRoot.XmlChildren[1],"twoatt",0);
WriteOutput(twoVar);
</cfscript>
Parameters:
Name | Description | Required |
---|---|---|
node | XML note to retrieve the attribute from. | Yes |
attribute | Attribute to retrieve. | Yes |
default | If attribute does not exist, return this default. | No |
Full UDF Source:
<!---
Pass in an XML Node and attribute reference to receive the attribute's value.
@param node XML note to retrieve the attribute from. (Required)
@param attribute Attribute to retrieve. (Required)
@param default If attribute does not exist, return this default. (Optional)
@return Returns a string.
@author Kreig Zimmerman (kkz@foureyes.com)
@version 1, December 23, 2002
--->
<cffunction name="GetXmlAttribute" output="false" returntype="any">
<cfargument name="node" type="any" required="yes">
<cfargument name="attribute" type="string" required="Yes">
<cfargument name="default" type="string" default="" required="false">
<cfset var myResult="#arguments.default#">
<cfif StructKeyExists(node.XmlAttributes, attribute)>
<cfset myResult=node.XmlAttributes["#attribute#"]>
</cfif>
<cfreturn myResult>
</cffunction>
Search CFLib.org
Latest Additions
Raymond Camden added
QueryDeleteRows
November 04, 2017
Leigh added
nullPad
May 11, 2016
Raymond Camden added
stripHTML
May 10, 2016
Kevin Cotton added
date2ExcelDate
May 05, 2016
Raymond Camden added
CapFirst
April 25, 2016