Reordering Xml Child Nodes

Discussion in 'Javascript' started by javascript@willasrari.com, Jan 26, 2007.

  1. Guest

    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
    , Jan 26, 2007
    #1
    1. Advertising

  2. 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/
    Martin Honnen, Jan 27, 2007
    #2
    1. Advertising

  3. Guest

    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
    , Jan 29, 2007
    #3
  4. Guest

    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>
    , Jan 29, 2007
    #4
  5. Guest

    Nevermind. Got it coach!
    , Jan 29, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. gavnosis
    Replies:
    0
    Views:
    500
    gavnosis
    Aug 2, 2003
  2. Jeff Rodriguez
    Replies:
    23
    Views:
    1,085
    David Schwartz
    Dec 9, 2003
  3. Replies:
    1
    Views:
    557
    Soren Kuula
    Aug 24, 2006
  4. th3dude
    Replies:
    0
    Views:
    424
    th3dude
    Jan 3, 2007
  5. Replies:
    1
    Views:
    1,193
    Joe Kesselman
    Nov 1, 2006
Loading...

Share This Page