Q:

Find all the XML nodes using coldfusion

I want to extract all the nodes(parent/children) with name "person" using coldfusion and make the value of the attribute "image1" as NULL
<person image1="img1.jpg" image2="img2.jpg">
    <person image1="img3.jpg" image2="img4.jpg" />
    <person image1="img5.jpg" image2="img6.jpg" />
</person>

A:

Here is a solution to your (edited) question using recursion: 
<cfset s = '<person image1="img1.jpg" image2="img2.jpg">
   <person image1="img3.jpg" image2="img4.jpg" />
   <person image1="img5.jpg" image2="img6.jpg" />
</person>' />

<cfset doc = xmlParse(s) />

<cfdump var="#doc#" label="before" />

<cfset myFunction(doc.xmlRoot) />

<cfdump var="#doc#" label="after" />

<!--- Function --->
<cffunction name="myFunction" output="true">
    <cfargument name="doc" type="xml" />

    <cfif ARGUMENTS.doc.xmlName eq "person">

        <cfloop collection="#ARGUMENTS.doc.xmlAttributes#" item="LOCAL.k">
            <p>#ARGUMENTS.doc.xmlAttributes[LOCAL.k]# set to null</p>
            <cfset ARGUMENTS.doc.xmlAttributes[LOCAL.k] = "null" />
        </cfloop>

    </cfif>

    <!--- Recursively call for children --->
    <cfloop array="#ARGUMENTS.doc.xmlChildren#" index="LOCAL.childElem">
        <cfset myFunction(LOCAL.childElem) />
    </cfloop>

</cffunction>

Hope that helps!

