Click here to Skip to main content
15,843,149 members
Home / Discussions / C#
   

C#

 
QuestionWeakReferences and the background garbage collector Pin
Judah Gabriel Himango16-May-06 9:48
sponsorJudah Gabriel Himango16-May-06 9:48 
AnswerRe: WeakReferences and the background garbage collector Pin
led mike16-May-06 10:22
led mike16-May-06 10:22 
GeneralRe: WeakReferences and the background garbage collector Pin
Judah Gabriel Himango16-May-06 12:11
sponsorJudah Gabriel Himango16-May-06 12:11 
AnswerRe: WeakReferences and the background garbage collector Pin
Guffa16-May-06 13:34
Guffa16-May-06 13:34 
QuestionXML and sorting Pin
donkaiser16-May-06 9:44
donkaiser16-May-06 9:44 
AnswerRe: XML and sorting Pin
Rei Miyasaka16-May-06 12:30
Rei Miyasaka16-May-06 12:30 
GeneralRe: XML and sorting Pin
donkaiser17-May-06 19:50
donkaiser17-May-06 19:50 
GeneralRe: XML and sorting Pin
Rei Miyasaka18-May-06 8:08
Rei Miyasaka18-May-06 8:08 
Ah, that was actually .NET 1.1 code. You can still make it work by adding
"using System.Collections" to the top of your code, but here's the .NET 2.0 version (you don't need BookComparer):

private static void SortXmlTest()
{
string data = @"<?xml version='1.0'?>
<Books>
<Book>
<Title>Advanced XML</Title>
<Publisher>Lucerne Publishing</Publisher>
</Book>
<Book>
<Title>Learn XML Today</Title>
<Publisher>MSPress</Publisher>
</Book>
<Book>
<Title>XML for Gurus</Title>
<Publisher>Lucerne Publishing</Publisher>
</Book>
<Book>
<Title>Developing XML solutions</Title>
<Publisher>MSPress</Publisher>
</Book>
</Books>";

//Create a new document and load the sample data.
XmlDocument doc = new XmlDocument();
doc.LoadXml(data);

//Copy all of the Book elements to a list.
List<XmlElement> books = new List<XmlElement>();
foreach (XmlElement book in doc.DocumentElement.ChildNodes)
books.Add(book);

//Sort the data -- if the publishers are the same, sort by title.
books.Sort(delegate(XmlElement x, XmlElement y)
{
int publisherCompare = x["Publisher"].InnerText.CompareTo(y["Publisher"].InnerText);
if (publisherCompare != 0)
return publisherCompare;

return x["Title"].InnerText.CompareTo(y["Title"].InnerText);
});

//Remove all the Book elements from the document, and put the sorted copy back in.
doc.DocumentElement.RemoveAll();

foreach (XmlElement book in books)
doc.DocumentElement.AppendChild(book);

//Print the data to the console.
doc.Save(Console.Out);
}
GeneralRe: XML and sorting Pin
donkaiser19-May-06 11:41
donkaiser19-May-06 11:41 
GeneralRe: XML and sorting [modifed] Pin
Rei Miyasaka19-May-06 14:54
Rei Miyasaka19-May-06 14:54 
QuestionJNI_CreateJavaVM Pin
pwimmers16-May-06 9:29
pwimmers16-May-06 9:29 
QuestionCollection was modified; Enumeration Operation may not execute Pin
Vijju200616-May-06 7:50
Vijju200616-May-06 7:50 
AnswerRe: Collection was modified; Enumeration Operation may not execute Pin
carlop()16-May-06 7:55
carlop()16-May-06 7:55 
GeneralRe: Collection was modified; Enumeration Operation may not execute Pin
Vijju200616-May-06 8:13
Vijju200616-May-06 8:13 
GeneralRe: Collection was modified; Enumeration Operation may not execute Pin
carlop()16-May-06 22:15
carlop()16-May-06 22:15 
QuestionA beginnering question Pin
mehrdadc4816-May-06 7:13
mehrdadc4816-May-06 7:13 
AnswerRe: A beginnering question Pin
Vikram A Punathambekar16-May-06 7:26
Vikram A Punathambekar16-May-06 7:26 
AnswerRe: A beginnering question Pin
coolvinx16-May-06 12:23
coolvinx16-May-06 12:23 
QuestionXML Remove Node Problem Pin
Phoen2516-May-06 7:07
Phoen2516-May-06 7:07 
AnswerRe: XML Remove Node Problem Pin
Phoen2516-May-06 7:40
Phoen2516-May-06 7:40 
QuestionRight click on flash player Pin
mehrdadc4816-May-06 6:58
mehrdadc4816-May-06 6:58 
Questionbuild vs rebuild Pin
mehrdadc4816-May-06 6:56
mehrdadc4816-May-06 6:56 
AnswerRe: build vs rebuild Pin
Rob Philpott16-May-06 6:59
Rob Philpott16-May-06 6:59 
AnswerRe: build vs rebuild Pin
Guffa16-May-06 8:09
Guffa16-May-06 8:09 
GeneralRe: build vs rebuild Pin
Robert Rohde16-May-06 9:17
Robert Rohde16-May-06 9:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.