xpath and sorting nodes

Discussion in 'ASP .Net' started by =?Utf-8?B?cGVsZWdrMQ==?=, Aug 8, 2007.

  1. i want to get nodes frm an xml using selectNoded,and then to sort them by an
    attribute.
    i have found this link :
    http://msdn2.microsoft.com/en-us/library/system.xml.xpath.xpathexpression.addsort(vs.71).aspx
    which describe how to sort nodes by there attribute value.

    i have a xml that loook like this :
    <Page>
    <MenuLinks>
    <Link isActive="1" innerOrder="4" val2="44">xxxx</Link>
    <Link isActive="1" innerOrder="2" val2="4424">d d d d d </Link>
    <Link isActive="0" innerOrder="14" val2="43244">ssssss</Link>
    <Link isActive="0" innerOrder="44" val2="1144">sdfsdfsdf</Link>
    <Link isActive="1" innerOrder="1" val2="46664">ertertertert</Link>
    </MenuLinks>
    </Page>
    and i want to get all of this that :
    isActive=1
    and ordered by innerOrder!
    and get from the relevent nodes there attribute->val2 value
    and the text() value of the node?
    the code i tried is :


    Dim doc As XPathDocument = New XPathDocument("C:\Inetpub\wwwroot\Page.xml")

    Dim nav As XPathNavigator = doc.CreateNavigator()

    'Select all books by Jane Austen.
    Dim expr As XPathExpression
    expr = nav.Compile("Page/MenuLinks/Link/@isActive='1'")

    'Sort the selected books by title.
    expr.AddSort("innerOrder", XmlSortOrder.Ascending,
    XmlCaseOrder.None, "", XmlDataType.Number)

    'Display the selection.
    Dim iterator As XPathNodeIterator = nav.Select(expr)
    While (iterator.MoveNext())
    Dim nav2 As XPathNavigator = iterator.Current.Clone()
    nav2.MoveToFirstChild()
    Console.WriteLine("Book title: {0}", nav2.Value)
    End While


    where do i go wrong?
    thnaks in adance
    peleg
     
    =?Utf-8?B?cGVsZWdrMQ==?=, Aug 8, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. asd
    Replies:
    3
    Views:
    440
    Arnaud Berger
    May 23, 2005
  2. gavnosis
    Replies:
    0
    Views:
    524
    gavnosis
    Aug 2, 2003
  3. Timo Nentwig

    selecting nodes between other nodes

    Timo Nentwig, Jun 16, 2004, in forum: XML
    Replies:
    1
    Views:
    409
    Patrick TJ McPhee
    Jun 17, 2004
  4. Johnny Ooi

    Looking A Nodes From Within Nodes

    Johnny Ooi, Nov 13, 2004, in forum: XML
    Replies:
    10
    Views:
    657
    Johnny Ooi
    Nov 14, 2004
  5. Replies:
    5
    Views:
    488
    bouton
    Sep 22, 2005
Loading...

Share This Page