**Sorting XML Nodes (ABC) 500 points!**

ok... I need my XML document / visitors nodes sorted by uniqueSN... here what I have so far...

Here's my XML file so far...

- - - - - - - - - - >>
    <viewedSN>T E S Ting</viewedSN>
    <lastVisit>10/30/2004 : 5:52:33 AM</lastVisit>

- - - - - - - - - - >>

Here's my VB.NET file so far...

- - - - - - - - - - >>
Dim viewedSN as String = Request.QueryString("ScreenName")
        Dim UniqueSN as String = CleanInput(viewedSN)
        Dim visitorDate as String = Request.QueryString("Date")
        Dim visitorTime as String = Request.QueryString("Time")
        Dim myScreenName as String = "myScreenName"
        Dim totalVisits as Integer

        Dim xmlPath As String = Server.MapPath("/Visitors.xml")
        Dim nList As XmlNodeList
        Dim n As XmlNode
        Dim nodeCount As Integer
        Dim myXMLdocument As XmlDocument = New XmlDocument()

        nList = myXMLdocument.SelectNodes("Visitors/visitor")
        nodeCount = nList.Count()

        Dim foundSN As String = "no"

        If (nList.Count > 0) Then
            For Each n In nlist 'if name matches
                If (n.ChildNodes.Item(0).InnerText = uniqueSN) Then
                    n.ChildNodes.Item(1).InnerText = viewedSN
                    n.ChildNodes.Item(2).InnerText += 1
                    totalVisits = CInt(n.ChildNodes.Item(2).InnerText)
                    n.ChildNodes.Item(3).InnerText = visitorDate + " : " + visitorTime
                    foundSN = "yes"
                    Exit For
                End If
        End If

        If (foundSN = "no") then

            'building XML Nodes
            Dim startNode As XmlNode = myXMLdocument.selectSingleNode("//Visitors")

            Dim nVisitor As XmlElement = myXMLdocument.CreateElement("visitor")

            Dim nUniqueSN As XmlElement = myXMLdocument.CreateElement("uniqueSN")
            nUniqueSN.InnerText = (uniqueSN)

            Dim nViewedSN As XmlElement = myXMLdocument.CreateElement("viewedSN")
            nViewedSN.InnerText = (viewedSN)

            Dim nTotalVisits As XmlElement = myXMLdocument.CreateElement("totalVisits")
            nTotalVisits.InnerText = ("1")

            Dim nLastVisit As XmlElement = myXMLdocument.CreateElement("lastVisit")
            nLastVisit.InnerText = (visitorDate + " : " + visitorTime)

            Dim nFirstVisit As XmlElement = myXMLdocument.CreateElement("firstVisit")
            nFirstVisit.InnerText = (visitorDate + " : " + visitorTime)


        End If


- - - - - - - - - - >>

Ok, now that you read all that, all I want to do is dort my XML document by uniqueSN.  When I create the new node / childs it adds it to the bottom and I would like the document sorted.  Can someone please help me?!

<< MM >>
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MoonbathingAuthor Commented:
Can anyone help me do a simple sort?
Bob LearnedCommented:
One way that you might try this is to add each node to a SortedList object, using the key necessary to sort in the correct order, and then read the entries from the SortedList.  NOTE:  This object will only work if you want ascending string sorts.

Put your xml doc into a dataset sort the dataset and re-populate your xml.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Bob LearnedCommented:
Ooh, another great suggestion :)

'Ooh, another great suggestion :)'

I hopes your not being sarcastic Bob...
MoonbathingAuthor Commented:
How would I go about populating it into a data set for manipulation?
Bob LearnedCommented:
No, I was being very serious, Tom.  I hadn't thought about using a DataSet.ReadXML and DataSet.WriteXML.  Very cool :)  You just haven't been around my sense of humor enough, I guess :)

I know you were Bob. I was just mee'in around with you.

Moonbathing I'll put something together for you.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.