Read/write XML? = me going crazy!

hey guys, i’m looking for a little guidance and expertise… i’ve got a portfolio built out of XML, which works great when pulling it from the xml file, but I want to build a simple admin page so that the XML can be added to, edited and then saved to the original file. I’ve looked around the web including kirupa, and tried to follow some advice, but i’m always getting php errors.

heres the actionscript i’m using: (the xml is sent to a php file displayed in a frame, btw)

menu_xml = new XML();
menu_xml.ignoreWhite = true;
menu_xml.load(“portfolio.xml”);
menu_xml.onLoad = function(ok) {
if(ok) {
xml_node = menu_xml;
menuOpen = 0;
buildMainMenu(menu_xml);

}

}

upload.onRelease = function() {

menu_xml.contentType = 'text/xml';

menu_xml.send(“update.php”,“mainFrame”)
}

and update.php uses the php source from this thread:
http://www.kirupaforum.com/forums/showthread.php?s=&threadid=49418&highlight=xml

the problem is, it doesn’t seem php even recieves the post variable… i tried even just echoing HTTP_RAW_POST_DATA, but its just blank… i’m also testing this on a server with PHP 4.x, is there something i’m missing?.. one of the most common errors i’m getting is ‘unexpected T_CONSTANT_ENCAPSED_STRING’… do i have to parse the XML somehow to get it to carry over? thanks.

this may help you http://www.kirupaforum.com/forums/showthread.php?t=51044

thanks for your help beetles. I found that one earlier, tho. However, after mulling over all the pages here and elsewhere around the web, i think i’ve got it… there must’ve been something wierd with the PHP code i was using.

Cool, do you know how to save it to xml via php then sort it in alphabetical order???

hrm… are you sorting them by their attributes? or their nodeNames?.. either way, i’m just guessing right now that the only way to do this is to pull them into an array, then sort the array, and then finally stick them back into XML.
I’ll keep my eyes open for any php function that might do this automatically, because i don’t think actionscript has an XML.sort function… I’m brand new to XML, really… i just started working with it like two days ago. But below is an idea i’m thinking might work for you (assuming the xml is already loaded and you want to sort the xml by its ‘name’ attribute)

num = XMLobj.firstChild.childNodes.length;

sortMe = new Array(num);

for(i=0;i<num;i++) {
sortMe* = XMLobj.firstChild.childNodes*.attributes.name;
}

sortMe.sort();

newNode = new XML();
newNode.createElement(“nodeName”);

for(i=0;i<num;i++) {
for(j=0;j<num;j++) {
if (sortMe* = XMLobj.firstChild.childNodes[j].attributes.name) {
newNode.firstChild.appendChild(XMLobj.firstChild.childNodes[j].cloneNode(true));
}
}

XMLobj.firstChild.removeNode();
XMLobj.appendNode(newNode.firstChild.cloneNode(true));

let me know if that helps…

-CC