Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Reordering Xml Child Nodes

Reply
Thread Tools

Reordering Xml Child Nodes

 
 
javascript@willasrari.com
Guest
Posts: n/a
 
      01-26-2007
I am wondering if it is possible to create a JavaScript function that
will re-order child nodes in an Xml Document. Currently I am binding
an Xml Data Island to an HTML table and implemented drag-and-drop
functionality.

Let's say I have the following:

Sequence 1
- 1
- 2
- 3
Sequence 2
- 4
- 5
- 6

The user re-orders so that:

Sequence 1
- 3
- 4
- 1

Sequence 2
- 5
- 6
- 2

Is it possible to sort each sequence's nodes from lowest to highest? I
have read about doing this with XSLT but figured I'd see if there was
an easier way.

Thanks in advance,

- will

 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      01-27-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> I am wondering if it is possible to create a JavaScript function that
> will re-order child nodes in an Xml Document. Currently I am binding
> an Xml Data Island to an HTML table and implemented drag-and-drop
> functionality.


> Is it possible to sort each sequence's nodes from lowest to highest?


Sure you can do that, the DOM allows you to reorder nodes by simply
inserting them where you want them. To sort you can put the DOM element
nodes in a JavaScript array and use the sort method with an appropriate
function to compare the text content of an element as a number.
Here is a simple example doing that with items in an XML data island
<http://home.arcor.de/martin.honnen/javascript/2007/01/test2007012701.html>
Note that XML data islands are IE specific.



--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
 
javascript@willasrari.com
Guest
Posts: n/a
 
      01-29-2007
Thanks Martin. I am aware that this is IE Specific. The client I am
developing this for is a Microsoft shop so that means that all
computers will be running IE 5.x+
In my spare time I am working on a Mozilla-friendly version using
C# .NET's Xml & Repeater web controls.

Thanks again,

- will

 
Reply With Quote
 
javascript@willasrari.com
Guest
Posts: n/a
 
      01-29-2007
What if I want to reorder Xml document using attributes? Each <item>
node will have multiple attributes. Let's say for sake of example I
want to reorder on itemId. How much more difficult would it be?

<root>
<product productId="1">
<item itemId="3" />
<item itemId="1" />
<item itemId="4" />
</product>
<product productId="2">
<item itemId="4" />
<item itemId="2" />
<item itemId="6" />
</product>
</root>

 
Reply With Quote
 
javascript@willasrari.com
Guest
Posts: n/a
 
      01-29-2007
Nevermind. Got it coach!


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dataset Question - Odd results with single xml nodes vs multiple nodes th3dude ASP .Net 0 01-03-2007 03:24 PM
select nodes with child node A and child node B gplott@yahoo.com XML 1 11-01-2006 09:27 PM
Selecting Nodes Using Subtotal of Child Nodes renfrochris@hotmail.com XML 1 08-24-2006 12:30 AM
How do I: Main thread spawn child threads, which child processes...control those child processes? Jeff Rodriguez C Programming 23 12-09-2003 11:06 PM
Reality check: Is it sensible to link XML nodes to other XML nodes in the same file? gavnosis XML 0 08-02-2003 08:22 AM



Advertisments