Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > xpath and sorting nodes

Reply
Thread Tools

xpath and sorting nodes

 
 
=?Utf-8?B?cGVsZWdrMQ==?=
Guest
Posts: n/a
 
      08-08-2007
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/lib...rt(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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
looping through names of nodes and sub nodes k.a.bouton@reading.ac.uk XML 5 09-22-2005 04:02 PM
Text nodes and element nodes query asd Java 3 05-23-2005 10:01 AM
Looking A Nodes From Within Nodes Johnny Ooi XML 10 11-14-2004 06:55 PM
selecting nodes between other nodes Timo Nentwig XML 1 06-17-2004 04:54 AM
Reality check: Is it sensible to link XML nodes to other XML nodes in the same file? gavnosis XML 0 08-02-2003 08:22 AM



Advertisments