Hi,

I've create a test case to illustrate a feature that was previously
working in 1.4 that now isn't in the nightly build of 18th Feb.

This is probably a lesser known behaviour that you can run an xpath on
an xml object make a change to the resultant search and this changes
the original xml. Very useful for being able to search, locate and
update nodes.

We now get an error about differing documents though.

@alan is this as result of the clone nodes to fix the xpath leak.

Thanks

Alex

<cfscript>
function
insertPropertyById(xmlDoc,nodeid,nodetype,propertyname,propertyvalue)
{
        var aParentNode = arrayNew(1);
        var nInsertPostion = 1;//Insert the node at the top
        //Check to see if this parentnode exists
        if(lcase(nodetype) eq "section"){
                //We are adding under a section
                aParentNode = xmlSearch(xmlDoc,"//
section[@uuid='#nodeid#']");
        }else{
                if(lcase(nodetype) eq "page"){
                        //We are adding under a page
                        aParentNode = xmlSearch(xmlDoc,"//
page[@page_uuid='#nodeid#']");
                }else{
                        aParentNode = xmlSearch(xmlDoc,"//
#nodetype#[@uuid='#nodeid#']");
                }
        }
        if(arrayLen(aParentNode)){
                ArrayInsertAt(aParentNode[1].xmlChildren,
nInsertPostion,
xmlElemNew(xmlDoc,"property"));
 
aParentNode[1].XmlChildren[nInsertPostion].xmlAttributes.name =
trim(propertyname);//Add the attributes to
this new child
 
aParentNode[1].XmlChildren[nInsertPostion].xmlAttributes.uuid =
createUUID();//Add the attributes to this
new child
                aParentNode[1].XmlChildren[nInsertPostion].xmlText =
PropertyValue;//
Add the attributes to this new child
        }
}

</cfscript>
<cfxml variable="application.xdoc">
<root>
<section uuid="1">
        <page page_uuid="1234" />
</section>
</root>
</cfxml>
<cfset
insertPropertyById(application.xdoc,"1","section","foo","bar")>
<cfdump var="#application.xdoc#">

-- 
tag/function ref: http://www.openbluedragon.org/manual/
 mailing list - http://groups.google.com/group/openbd?hl=en

 Get to Texas in Feb for OpenCFSummit http://www.opencfsummit.org/

Reply via email to