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.
<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#">
<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>
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.
Archived Comments
ray,
in many use cases we can have an xml configuration/setup file, and often we have to change any of the items to change a behaviour, at runtime, so this post is very usefull.
Good to know :)
Please note that XMLSearch can also return simple values (I <a href="http://twitter.com/#!/dorin...">twitted</a> about this).
Ah nice - I ran into this once myself I think in an AIR application but forgot about it. :)