|
Re: An XML Design Possibility Question: msg#00096windows.devel.dotnet.web
Hi Robert, the code snippet beneath should get you started. I also tried to "paginate" the selected nodes with nav.Compile("data/book[((position()-1) mod 2) = 0]"); but it seems the sorting is being applied afterwards, making the "paginating" useless... // Ryan using System.Xml; using System.Xml.XPath; using System.IO; XPathDocument doc = new XPathDocument( new StringReader( @"<data> <book> <title>ZTitle</title> <author>Aauthor</author> <isbn>3</isbn> </book> <book> <title>YTitle</title> <author>Dauthor</author> <isbn>55</isbn> </book> <book> <title>BTitle</title> <author>Bauthor</author> <isbn>2</isbn> </book> <book> <title>ATitle</title> <author>Cauthor</author> <isbn>10</isbn> </book> </data> ")); XPathNavigator nav = doc.CreateNavigator(); XPathExpression expr; expr = nav.Compile( "data/book"); expr.AddSort( "title", XmlSortOrder.Ascending, XmlCaseOrder.None, "", XmlDataType.Text); //expr.AddSort( "author", XmlSortOrder.Ascending, XmlCaseOrder.None, "", XmlDataType.Text); //expr.AddSort( "isbn", XmlSortOrder.Ascending, XmlCaseOrder.None, "", XmlDataType.Number); XPathNodeIterator iterator = nav.Select( expr); while ( iterator.MoveNext()) { XPathNavigator nav2 = iterator.Current; nav2.MoveToFirstChild(); Console.WriteLine( "{0}:{1}", nav2.Value, iterator.CurrentPosition); } =================================== This list is hosted by DevelopMentor® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: An XML Design Possibility Question: 00096, Robert Dickson |
|---|---|
| Next by Date: | navigation to anchor: 00096, Alex Smotritsky |
| Previous by Thread: | Re: An XML Design Possibility Questioni: 00096, Robert Dickson |
| Next by Thread: | navigation to anchor: 00096, Alex Smotritsky |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |