The project has now been updated. You could now do:

<cfscript>
   attributes = StructNew();
   attributes['id'] = 23

   oXml.CreateElement('//[EMAIL PROTECTED]"#theId#"]', 'newelement', 'This
is some element content.', attributes);
</cfsript>

You can also now supply an xml string to either CreateElement or
Update as the value of the element (and it won't be escaped as it was
before):

<cfscript>
   theContentToAdd= '<p id="foo">Hello <strong>world</strong></p>';
   oXml.Update('//[EMAIL PROTECTED]"#theId#"]',  theContentToAdd);
</cfscript>

Dominic

2008/7/11 Dominic Watson <[EMAIL PROTECTED]>:
> Its been a long time since I looked at the component and haven't had
> any feedback so this is great. I think a better way would be to modify
> the CreateElement method to allow an extra optional argument for
> attributes (would be a struct).
>
> To do what you are doing, you don't actually have to modify the code.
> You could use CreateAttribute and supply an XPath that selects only
> elements without the id attribute (I'm not sure of the XPath for this
> offhand, googlable tho).
>
> I'll add the issue to the tracker.
>
> Dominic
>
> 2008/7/11 Cindi Vinette <[EMAIL PROTECTED]>:
>> Not sure if there is a better way, but I fixed my issue by modifying your 
>> "CreateAttribute" function - checking first to see if the attribute that i 
>> was trying to create already existed, and only adding it if not. That way, 
>> if I set the value immediately after adding the new child element, there is 
>> only one to set...
>>
>> // check to see if this already has this attribute set
>>                                        
>> if(pNodes.item(javacast('int',i)).GetAttribute('#arguments.name#') eq ""){
>>                                                
>> pNodes.item(javacast('int',i)).SetAttribute(arguments.name, arguments.value);
>>                                        }
>>
>> Cindi
>>
>>> This is really great. The only thing that I can't figure out how to do
>>> is how to create an element and set an attribute at the same time. I
>>> need to create an element and give it an "id" attribute...
>>>
>>> Any suggestions?
>>>
>>> Otherwise, this rocks. Finds the exact thing that I'm looking for
>>> right away and adds an element to it...
>>>
>>> Cindi
>>>
>>>
>>>
>>>
>>> >I think this is the perfect situation for my betterXml component:
>>> >
>>> >http://betterxml.riaforge.org
>>> >
>>> >With it you could do this with only a few lines of code (XPath
>>> required), ie.
>>> >
>>> >oXml = CreateObject('component', 'betterXmlEditor').init(xmlSource);
>>> >// xml string, file or url for the source
>>> >
>>> >oXml.Update('//[EMAIL PROTECTED]"#theId#"]',  theContentToAdd); //
>>> updates
>>> >all elements with id="#theId#" with theContentToAdd (can be either
>>> >structure or plain string);
>>> >oXml.Write(xmlFilePath);
>>> >
>>> >HTH
>>> >
>>> >Dominic
>>> >>
>>
>>
>> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to 
date
Get the Free Trial
http://ad.doubleclick.net/clk;203748912;27390454;j

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:308973
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to