Results of ColdFusion's XMLSearch functions are references

Just a quick note. I was talking with Stephen Moretti about working with the results of the XMLSearch function. He wanted to know if the results were references or copies of the XML data. I did a few tests and from what I see - they are references. Here is a quick example.

<cfxml variable="stuff"> <products> <product name="alpha"> <price>10</price> </product> <product name="beta"> <price>11</price> </product> <product name="gamma"> <price>9</price> </product> </products> </cfxml> <cfdump var="#stuff#"> <cfset b = xmlSearch(stuff, "//product[@name='beta']")> <cfdump var="#b#"> <cfset test = b[1]> <cfset test.xmlchildren[1].xmltext =99> <cfset test.xmlattributes.name = "boo"> <cfdump var="#stuff#">

I begin with a simple XML packet of products. Each product has a name and a price child. I do a search to find the Beta product. Once I've got it I manipulate the name and the price. Here are the results of the dumps:

Not sure how useful this is - I almost never actually update XML - but hopefully this will help others.

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