HI,
I'm trying to sort this list of xml data alphabetically (supplier name) but for some reason this code is not working. Coud you help? Thanks!
My xml
CONTRACTS
-CONTRACT
---SUPPLIER
----SUPPLIERID
----SUPPLIERNAME
My .net.vb page
I'm trying to sort this list of xml data alphabetically (supplier name) but for some reason this code is not working. Coud you help? Thanks!
My xml
CONTRACTS
-CONTRACT
---SUPPLIER
----SUPPLIERID
----SUPPLIERNAME
My .net.vb page
Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim myString As StringBuilder = New StringBuilder(100)
Dim xdoc As New XPathDocument(AppDomain.CurrentDomain.BaseDirectory + "/cupid/local_xml.xml")
Dim nav As XPathNavigator = xdoc.CreateNavigator()
Dim expr As XPathExpression
expr = nav.Compile("/pf:CONTRACTS/pf:CONTRACT/pf:SUPPLIERS/pf:SUPPLIER[not(pf:SUPPLIERID=preceding::pf:SUPPLIER/pf:SUPPLIERID)]")
Dim namespaceManager As XmlNamespaceManager = New XmlNamespaceManager(nav.NameTable)
namespaceManager.AddNamespace("pf", "http://namespace.com/")
expr.AddSort("/pf:CONTRACTS/pf:CONTRACT/pf:SUPPLIERS/pf:SUPPLIER/pf:SUPPLIERNAME", XmlSortOrder.Ascending, XmlCaseOrder.None, String.Empty, XmlDataType.Text)
expr.SetContext(namespaceManager)
Dim nodes As XPathNodeIterator = nav.Select(expr)
If nodes.Count > 0 Then
Dim tr As String = Nothing
myString.AppendLine("<table width='300px' border='0' cellpadding='0' cellspacing='0' border='0' class='datatable1'>")
myString.AppendLine("<th>Supplier name</th>")
While nodes.MoveNext()
Dim sChars As String = " "
Dim supplier As XPathNavigator = nodes.Current.SelectSingleNode("pf:SUPPLIERNAME", namespaceManager)
Dim supplierID As XPathNavigator = nodes.Current.SelectSingleNode("pf:SUPPLIERID", namespaceManager)
myString.AppendLine("<tr><td><a href=""javascript:poptastic('http://www.cupid.ac.uk/Supplier/SupplierDisplay.aspx?supplierId=" & supplierID.ToString() & "');"">" & supplier.ToString.TrimEnd(sChars) & "</a>")
myString.AppendLine("</td></tr>")
End While
myString.AppendLine("</table>")
Dim strOutput As String = myString.ToString()
lblOutput.Text = strOutput
Else
lblOutput.Text = "No results for your search"
End If
End Sub
Comment