tags:

views:

63

answers:

1

I was playing around onError so I tried to create an error using a large xml document object.

<cfset XMLByRef = variables.parsedXML.XMLRootElement.XMLChildElement>
<cfset structDelete(variables.parsedXML, "XMLRootElement")>
<cfset startXMLShortLoop = getTickCount()>
<cfloop from = "1" to = "#arrayLen(variables.XMLByRef)#" index = "variables.i">
  <cfoutput>#variables.XMLByRef[variables.i].id.xmltext#</cfoutput><br />
</cfloop>
<cfset stopXMLShortLoop = getTickCount()>

I expected to get an error because I deleted the structure I was referencing.

From LiveDocs:

Variable Assignment - Creates an additional reference, or alias, to the structure. Any change to the data using one variable name changes the structure that you access using the other variable name. This technique is useful when you want to add a local variable to another scope or otherwise change a variable's scope without deleting the variable from the original scope.

instead I got

580df1de-3362-ca9b-b287-47795b6cdc17

25a00498-0f68-6f04-a981-56853c0844ed

... ... ...

db49ed8a-0ba6-8644-124a-6d6ebda3aa52

57e57e28-e044-6119-afe2-aebffb549342

Looped 12805 times in 297 milliseconds

<cfdump var = "#variables#">

Shows there's nothing in the structure, just parsedXML.xmlRoot.xmlName with the value of XMLRootElement. I also tried

<cfset structDelete(variables.parsedXML.XMLRootElement, "XMLChildElement")>

as well as structClear for both.

More information on deleting from the xml document object. http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec22c24-78e3.html

Can someone please explain my faulty logic? Thanks.

+2  A: 

XML data types are a combination of structures and arrays. Unlike Structures, Arrays in CF will pass by value and not by reference and may be what you are seeing.

http://www.coldfusionjedi.com/index.cfm/2009/5/1/ColdFusion-and-Pass-by-Reference-versus-Value

shooksm
That kinda makes sense and it's probably the answer. Does anyone know why I get these results for "parsedXML.XMLRootElement.XMLChildElement?" isArray: NO isStruct: NO isObject: NO isQuery: NO isSimpleValue: NO isXML: YES isXMLDoc: NO isXMLElem: YES isXMLNode: YES isXMLRoot: NO structKeyExists: YES arrayLen: 12804. isArray and isStruct are both now but structKeyExists is yes and and arrayLen has a value and it copies by value like an array?
Travis
oh, nevermind: The following table lists the ColdFusion array and structure functions that you can use to manage XML document objects and their functions, and describes their common uses. In several cases you can use either an array function or a structure function for a purpose, such as for deleting all of an element's attributes or children.
Travis