Copy link to clipboard
Copied
Copy link to clipboard
Copied
While most of the array functions and notation works fine with XML objects, ArrayInsertAt() is not one of them.
You probably want the xmlElemNew() function, check out the other XML functions. http://livedocs.adobe.com/coldfusion/8/htmldocs/functions-pt0_21.html#3468770
Copy link to clipboard
Copied
thanks for the response but it does not seem to change anything. i modified my code to
<cfset xApps.xmlRoot.XmlChildren[1] = XmlElemNew(xApps,"message") />
thinking this would place messages into the first child and renumber the exsiting children. it did not and instead placed messages first under messageList as this:
<messageList>
<message/>
i am looking to get to this point where i insert a new message before or after an existing one
<messageList>
<message>
</message>
<message>
<sender>JONES</sender>
</message>
</messageList>
thanks for your time
Copy link to clipboard
Copied
Ok, so it takes a combination of arrayInsertAt, which I now know does work on xml objects, and xmlElemNew.
<cfsavecontent variable="xml">
<messageList>
<message>
<sender>SMITH</sender>
</message><message>
<sender>JONES</sender>
</message></messageList>
</cfsavecontent><cfset xmlObj = xmlParse(xml)>
<cfdump var="#xmlObj#">
<cfset arrayInsertAt(xmlObj.messageList.xmlChildren,1,xmlElemNew(xmlObj,'message'))>
<cfdump var="#xmlObj#">
Copy link to clipboard
Copied
yes this does work fine. actually all the examples where xml is created from scratch ,work fine. i need to read an existing xml file and add to it.
this does not do that nor do any examples found to this point do that. am i wasting my time trying to do this in cf? should i be looking into another technology to update an xml file?
thank you for your time.
Copy link to clipboard
Copied
wait......... that last example you sent has much better results...... it placed the sender in the xml doc with the correct results. let me fool around with this and get back to you. i had something similar but without your results.
thanks for your time
Copy link to clipboard
Copied
Hello, let me add my two cents:
I came accross the same situation for a photo gallery I needed my client to change. It is a flash/xml photo gallery and the client wanted to change/add/delete images.
My solution (which for sure is not the best, but it works) is:
1) Every time the client adds a picture to the gallery, I write the info into the database.
2) Then I call a page that runs the cfxml tag and within the tag it runs a query on that table. This query forms the updated xml file and replaces the old one.
I hope this was clear, otherwise I can send you the code.
Cheers,
Copy link to clipboard
Copied
A slightly more complete example I played with because I was curious.
<cfdump var="#xmlObj#">
<cfset arrayInsertAt(xmlObj.messageList.xmlChildren,1,xmlElemNew(xmlObj,'message'))>
<cfset xmlObj.messageList.message[1].sender = xmlElemNew(xmlObj,'sender')>
<cfset xmlObj.messageList.message[1].sender.xmlText = "PIERRE"><cfdump var="#xmlObj#">