problem with AddSort method

Posted by netNewbi3 on Stack Overflow See other posts from Stack Overflow or by netNewbi3
Published on 2010-03-26T12:18:10Z Indexed on 2010/03/26 12:23 UTC
Read the original article Hit count: 480

Filed under:
|
|

Hi

Could you let me know what the proboem is with sorting in this code? It doesn't work.

My xml:

CONTRACTS
--CONTRACT
---SUPPLIER
---COMMODITIES
----COMMODITY
-----COMODDITYNAME

My code:

    Dim myString As StringBuilder = New StringBuilder(200) 
    Dim xdoc As New XPathDocument("local_xml.xml") 

    Dim nav As XPathNavigator = xdoc.CreateNavigator() 
    Dim expr As XPathExpression 
    expr = nav.Compile("/pf:CONTRACTS/pf:CONTRACT") 

    Dim namespaceManager As XmlNamespaceManager = New XmlNamespaceManager(nav.NameTable) 
    namespaceManager.AddNamespace("pf", "http://namespace.ac.uk/") 
    expr.AddSort("pf:SUPPLIER", XmlSortOrder.Ascending, XmlCaseOrder.None, String.Empty, XmlDataType.Text) 
    expr.SetContext(namespaceManager) 

    Dim nodes As XPathNodeIterator = nav.Select(expr) 

    If nodes.Count > 0 Then 

        myString.AppendLine("<table width='96%' border='0' cellpadding='0' cellspacing='0' border='0' class='datatable1'>") 
        myString.AppendLine("<th width='35%'>Name</th><th width='35%'>Commodity</th><th width='20%'>Supplier</a></th>") 

        While nodes.MoveNext() 

            Dim node As XPathNavigator = nodes.Current.SelectSingleNode("pf:NAME", namespaceManager) 
            Dim supplier As XPathNavigator = nodes.Current.SelectSingleNode("pf:SUPPLIER", namespaceManager) 
            Dim commodity As XPathNavigator = nodes.Current.SelectSingleNode("pf:COMMODITIES/pf:COMMODITY/pf:COMMODITYNAME", namespaceManager) 

            Dim sChars As String = " " 
            myString.AppendLine("<tr>") 
            myString.AppendLine("<td>") 
            myString.AppendLine(node.ToString()) 
            myString.AppendLine("</td>") 
            myString.AppendLine("<td>") 
            myString.AppendLine(commodity.ToString()) 
            myString.AppendLine("</td>") 
            myString.AppendLine("<td>") 
            myString.AppendLine(supplier.ToString()) 
            myString.AppendLine("</td>") 
            myString.AppendLine("</tr>") 

        End While 

        myString.AppendLine("</table>") 

        Dim strOutput As String = myString.ToString() 
        lblOutput.Text = strOutput 

    Else 

        lblOutput.Text = "No results for your search<br/>" 

    End If 

© Stack Overflow or respective owner

Related posts about .NET

Related posts about xpath