# Read/write XML? = me going crazy!

**URL:** https://forum.kirupa.com/t/read-write-xml-me-going-crazy/111427
**Category:** Uncategorized
**Created:** [May 26, 2004, 8:40pm UTC](https://forum.kirupa.com/t/read-write-xml-me-going-crazy/111427 "2004-05-26T20:40:25Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![CommanderCool](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/commandercool/32/158_2.png) [@CommanderCool](https://forum.kirupa.com/u/CommanderCool)
#### Post date: [May 26, 2004, 8:40pm UTC](https://forum.kirupa.com/t/read-write-xml-me-going-crazy/111427/1 "2004-05-26T20:40:25Z")

</div>

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](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.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [May 26, 2004, 11:19pm UTC](https://forum.kirupa.com/t/read-write-xml-me-going-crazy/111427/2 "2004-05-26T23:19:07Z")

</div>

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

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [May 27, 2004, 6:44pm UTC](https://forum.kirupa.com/t/read-write-xml-me-going-crazy/111427/3 "2004-05-27T18:44:05Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [May 28, 2004, 8:50am UTC](https://forum.kirupa.com/t/read-write-xml-me-going-crazy/111427/4 "2004-05-28T08:50:56Z")

</div>

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

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [May 28, 2004, 6:09pm UTC](https://forum.kirupa.com/t/read-write-xml-me-going-crazy/111427/5 "2004-05-28T18:09:35Z")

</div>

> [@lbeetles](#):
>
> 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
