473,396 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Reordering Xml Child Nodes

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 '07 #1
4 6192
ja********@willasrari.com 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/
Jan 27 '07 #2
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 '07 #3
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 '07 #4
Nevermind. Got it coach!
Jan 29 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: kaeli | last post by:
Can anyone explain this to me? It's driving me insane. Save this and run it in IE or Opera and then in Mozilla or Netscape 6+. In IE/Opera, I get the expected 4 alerts. In Mozilla/Netscape, I...
1
by: Hazz | last post by:
I have 5 tables in SQL Server. Each with the following design and a sample chain of the relationships from the root (WRL - World) UUS is the 'Code' of the first table and it is the 'Parent' value...
12
by: Dino L. | last post by:
I am putting data from DataTable to treeView foreach( DataRow aRow in aTable.Rows) { TreeNode tnode = new TreeNode(aRow.ToString() + aRow.ToString() + " " + aRow.ToString());...
7
by: amruta | last post by:
the code below dows not let me get the parent child view... all the nodes are show in one line only... also i need them to be collasped ... Thanks ..
2
by: Jack | last post by:
Hello, I am trying use a TreeView with checkboxes. I would like to check more than one node and allow all child nodes of selected nodes to be checked or unchecked with the parent is checked. ...
1
by: Daniel Rucareanu | last post by:
Hello, Does anybody knows how can you delete, in just one step, not using a loop, a subset of the child nodes of a given DOM parent node? The subset will be continous, so for example, if the...
2
by: GreggaR0und | last post by:
Hello; I'm trying to iterate through the sub nodes of a child node, but I'm getting a compile error on the nested For...Next expression saying it is invalid. Using the below code, the HasChild()...
0
by: divya1949 | last post by:
Create a windows c# application which will Read a xml file and populate nodes in the treeview. 1 On selection of treenode display the child nodes of that node in listview control 2. ...
2
by: arggg | last post by:
I am trying to add child nodes based on database query in which the users in the database are a part of the parent node. Here is my code. private void GetUsersByGroup() { ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.