Ask a Jedi: ColdFusion and XML Attributes

Chris asks:

Can CF7 read this type of XML entry? I'm having problems reading it... <Bios name="Phoenix ROM BIOS PLUS Version 1.10 A04" date="(17-May-2004)"/>

So I knew the answer to this was yes, but to be sure, I wrote up a quick test case:

<cfxml variable="test"> <Bios name="Phoenix ROM BIOS PLUS Version 1.10 A04" date="(17-May-2004)"/> </cfxml>

<cfdump var=”#test#”> </code>

This dumped the XML just fine, and revealed the hint that Chris probably needed to read the data. The name and date value exist in the xmlAttributes key. So in order to get those specific values (assuming he has already created an XML object called test, as I did above), he could use the following code:

<cfoutput> Name: #test.bios.xmlAttributes.name#<br/> Date: #test.bios.xmlAttributes.date#<br/> </cfoutput>

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Comments