logo       

Re: An XML Design Possibility Question: msg#00096

windows.devel.dotnet.web

Subject: Re: An XML Design Possibility Question

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>
Google Custom Search

News | FAQ | advertise