xpath and sorting nodes

G

Guest

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top