Groups | Blog | Home
all groups > dotnet xml > november 2004 >

dotnet xml : Swap pointers?


Lidström
11/24/2004 4:50:41 PM
Hi,

is there a method somewhere in the framework for swapping two pointers?

--
Daniel
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Martin Honnen
11/24/2004 5:48:00 PM


[quoted text, click to view]


[quoted text, click to view]

This is an XML group for .NET, managed code in .NET doesn't know
pointers, there are value types and reference types.
If you want to swap to nodes in an XmlDocument then you can do so by
inserting one node before the other and then moving the second node to
the old position:
boolean swapNodes (XmlNode node1, XmlNode node2) {
if (node1.OwnerDocument == node2.OwnerDocument &&
node1.ParentNode != null &&
node2.ParentNode != null) {
XmlNode sibling = node1.NextSibling;
XmlNode parentNode = node1.ParentNode;
node2.ParentNode.InsertBefore(node1, node2);
parentNode.insertBefore(node2, sibling);
return true;
}
else {
return false;
}
}
Untested but should show you what to do.


--

Martin Honnen
AddThis Social Bookmark Button