all groups > dotnet xml > january 2006 >
You're in the

dotnet xml

group:

Using Xpath functions?



Using Xpath functions? amessimon
1/30/2006 12:15:33 PM
dotnet xml: Hi, im trying to use the Xpath function "reverse" with an XmlTextReader.

Im not sure if i need to add a namespace to reference this function or
what, if so whats the address of the namespace. Can anyone give me an
idea where i am going wrong here?

So far....

Dim strXmlFeedUrl As String = server.mappath("test.xml")
Dim reader As XmlTextReader = New XmlTextReader(strXmlFeedUrl)
Dim xmlDoc = New XmlDocument
xmlDoc.Load(reader)
Dim urlArticleNodes As XmlNodeList =
xmlDoc.SelectNodes("reverse(/Articles/Article)")

Im getting the error...

"Namespace Manager or XsltContext needed. This query has a prefix,
variable, or user-defined function."

Re: Using Xpath functions? Martin Honnen
1/30/2006 1:28:03 PM


[quoted text, click to view]

XPath 1.0 does not define any such function of that name:
<http://www.w3.org/TR/xpath#corelib>
..NET 1.x and 2.0 only supports XPath 1.0 and a few Microsoft extensions,
those for .NET 2.0 are listed here:
<http://msdn2.microsoft.com/en-us/library/ms256138(en-US,VS.80).aspx>


I guess you have been fooled by someone documentating XPath 2.0
functionality
<http://www.w3.org/TR/xquery-operators/#func-reverse>
without making it clear that the version is XPath 2.0 and that XPath 2.0
is not even a W3C recommendation (read: standard) but only on its way to
standardization.
--

Martin Honnen --- MVP XML
Re: Using Xpath functions? amessimon
1/30/2006 1:46:39 PM
Thanks for pointing that Martin. Basically i am looking to order the
nodes i am selecting in the reverse order they appear in the document.

I would not be ordering by any particular node or attribute, just the
reverse of the order in the document.

eg: "/Articles/Article" in reverse order

Does anyone know a way to do this?



[quoted text, click to view]
Re: Using Xpath functions? Martin Honnen
1/30/2006 3:21:01 PM


[quoted text, click to view]

Well if simply loop through the node list from end to beginning e.g.
pseudo code

Dim Articles As XmlNodeList = _
Xml_Document.SelectNodes("/Articles/Article")
For I As Integer = Articles.Count - 1 To 0 Step -1
Console.WriteLine(Articles(I).OuterXml)
Next

you can process the returned node list in reverse order.

XPathExpression and XPathNavigator would allow you to do some sorting if
needed but for the above that is not necessary.


--

Martin Honnen --- MVP XML
Re: Using Xpath functions? Sonu Kapoor
2/1/2006 8:06:15 PM
A very good resource for XPath functions:

http://www.w3schools.com/xpath/

Sonu Kapoor [MVP]
---
AddThis Social Bookmark Button