Moonbathing
asked on
**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...
- - - - - - - - - - >>
<Visitors>
<visitor>
<uniqueSN>testing</uniqueS N>
<viewedSN>T E S Ting</viewedSN>
<totalVisits>16</totalVisi ts>
<lastVisit>10/30/2004 : 5:52:33 AM</lastVisit>
<firstVisit>
</firstVisit>
</visitor>
</Visitors>
- - - - - - - - - - >>
Here's my VB.NET file so far...
- - - - - - - - - - >>
Dim viewedSN as String = Request.QueryString("Scree nName")
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()
myXMLdocument.Load(xmlPath )
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).Inne rText = uniqueSN) Then
n.ChildNodes.Item(1).Inner Text = viewedSN
n.ChildNodes.Item(2).Inner Text += 1
totalVisits = CInt(n.ChildNodes.Item(2). InnerText)
n.ChildNodes.Item(3).Inner Text = visitorDate + " : " + visitorTime
foundSN = "yes"
Exit For
End If
Next
End If
If (foundSN = "no") then
'building XML Nodes
Dim startNode As XmlNode = myXMLdocument.selectSingle Node("//Vi sitors")
Dim nVisitor As XmlElement = myXMLdocument.CreateElemen t("visitor ")
Dim nUniqueSN As XmlElement = myXMLdocument.CreateElemen t("uniqueS N")
nUniqueSN.InnerText = (uniqueSN)
Dim nViewedSN As XmlElement = myXMLdocument.CreateElemen t("viewedS N")
nViewedSN.InnerText = (viewedSN)
Dim nTotalVisits As XmlElement = myXMLdocument.CreateElemen t("totalVi sits")
nTotalVisits.InnerText = ("1")
Dim nLastVisit As XmlElement = myXMLdocument.CreateElemen t("lastVis it")
nLastVisit.InnerText = (visitorDate + " : " + visitorTime)
Dim nFirstVisit As XmlElement = myXMLdocument.CreateElemen t("firstVi sit")
nFirstVisit.InnerText = (visitorDate + " : " + visitorTime)
startNode.AppendChild(nVis itor)
nVisitor.AppendChild(nUniq ueSN)
nVisitor.AppendChild(nView edSN)
nVisitor.AppendChild(nTota lVisits)
nVisitor.AppendChild(nLast Visit)
nVisitor.AppendChild(nFirs tVisit)
End If
myXMLdocument.Save(xmlPath )
- - - - - - - - - - >>
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 >>
Here's my XML file so far...
- - - - - - - - - - >>
<Visitors>
<visitor>
<uniqueSN>testing</uniqueS
<viewedSN>T E S Ting</viewedSN>
<totalVisits>16</totalVisi
<lastVisit>10/30/2004 : 5:52:33 AM</lastVisit>
<firstVisit>
</firstVisit>
</visitor>
</Visitors>
- - - - - - - - - - >>
Here's my VB.NET file so far...
- - - - - - - - - - >>
Dim viewedSN as String = Request.QueryString("Scree
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.
Dim nList As XmlNodeList
Dim n As XmlNode
Dim nodeCount As Integer
Dim myXMLdocument As XmlDocument = New XmlDocument()
myXMLdocument.Load(xmlPath
nList = myXMLdocument.SelectNodes(
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).Inne
n.ChildNodes.Item(1).Inner
n.ChildNodes.Item(2).Inner
totalVisits = CInt(n.ChildNodes.Item(2).
n.ChildNodes.Item(3).Inner
foundSN = "yes"
Exit For
End If
Next
End If
If (foundSN = "no") then
'building XML Nodes
Dim startNode As XmlNode = myXMLdocument.selectSingle
Dim nVisitor As XmlElement = myXMLdocument.CreateElemen
Dim nUniqueSN As XmlElement = myXMLdocument.CreateElemen
nUniqueSN.InnerText = (uniqueSN)
Dim nViewedSN As XmlElement = myXMLdocument.CreateElemen
nViewedSN.InnerText = (viewedSN)
Dim nTotalVisits As XmlElement = myXMLdocument.CreateElemen
nTotalVisits.InnerText = ("1")
Dim nLastVisit As XmlElement = myXMLdocument.CreateElemen
nLastVisit.InnerText = (visitorDate + " : " + visitorTime)
Dim nFirstVisit As XmlElement = myXMLdocument.CreateElemen
nFirstVisit.InnerText = (visitorDate + " : " + visitorTime)
startNode.AppendChild(nVis
nVisitor.AppendChild(nUniq
nVisitor.AppendChild(nView
nVisitor.AppendChild(nTota
nVisitor.AppendChild(nLast
nVisitor.AppendChild(nFirs
End If
myXMLdocument.Save(xmlPath
- - - - - - - - - - >>
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 >>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Ooh, another great suggestion :)
Bob
Bob
'Ooh, another great suggestion :)'
I hopes your not being sarcastic Bob...
I hopes your not being sarcastic Bob...
ASKER
How would I go about populating it into a data set for manipulation?
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 :)
Bob
Bob
I know you were Bob. I was just mee'in around with you.
Moonbathing I'll put something together for you.
Moonbathing I'll put something together for you.
ASKER