Click to See Complete Forum and Search --> : New node will appear at the top of the tree


redice
06-18-2009, 05:32 AM
Hi all,

Right now, each time a new node is added, it'll append on the bottom of the xml file. Example (red node is the newly added node):


<contents>
<Content>
<id>
<name>
<email>
</Content>
<Content>
<id>
<name>
<email>
</Content>
</contents>


How do I append it on top instead? Thus, it'll look something like this:


<contents>
<Content>
<id>
<name>
<email>
</Content>
<Content>
<id>
<name>
<email>
</Content>
</contents>


Currently, I am using .asp to develop the page. I've once wanted to sort the XML when I display it on the page, but research shown I need to use XSLT, which I am reluctant too.

Any advice?

Perhaps I can still append it on the bottom but during display, I sort the "id" descendingly?

Thank you in advance!

jkmyoung
06-19-2009, 03:40 PM
Create a new parent node.
Add the new child node in.
Add the old children in. (You may have to clone nodes).
Do a replaceNode: oldparent with newparent.

redice
06-21-2009, 10:32 PM
Hi jkmyoung,

Do you have a sample code for this?

jkmyoung
06-22-2009, 10:51 AM
Are you still intending to use ASP/XML?

Possibly (depending on what you're using), there is also the insertbefore function:
http://www.w3schools.com/dom/dom_nodes_add.asp

This is a better solution, if applicable on your system.