Update of /cvsroot/mvp-xml/Common/v2/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1205/v2/test Added Files: .cvsignore AssemblyInfo.cs CommonTest.csproj DebugUtils.cs DebuggingXPathNavigator.cs DebuggingXmlTextReader.cs Globals.cs IndexingXPathNavigatorTest.cs Misc.cs XPathCacheTests.cs XPathCacheUsability.cs XPathSortBug.cs XmlNodeFactoryTests.cs XmlNodeListFactoryTests.cs changelog.txt library.xml northwind.xml pubs.xml pubsNs.cs pubsNs.xml pubsNs.xsd Log Message: --- NEW FILE: CommonTest.csproj --- (This appears to be a binary file; contents omitted.) --- NEW FILE: .cvsignore --- bin obj *.user *.suo --- NEW FILE: DebugUtils.cs --- using System; using System.Xml; using System.Xml.XPath; namespace Mvp.Xml.Tests { /// <summary> /// Miscelaneous debug utilities. /// </summary> public class DebugUtils { private DebugUtils() {} public static void XPathNodeIteratorToConsole(XPathNodeIterator iterator) { Console.WriteLine(new string('-', 50)); XmlTextWriter tw = new XmlTextWriter(Console.Out); tw.Formatting = Formatting.Indented; while (iterator.MoveNext()) { tw.WriteNode(iterator.Current.ReadSubtree(), false); } tw.Flush(); Console.WriteLine(); Console.WriteLine(new string('-', 50)); } } } --- NEW FILE: Globals.cs --- using System; using System.IO; namespace Mvp.Xml.Tests { /// <summary> /// Loads test documents. /// </summary> public sealed class Globals { public const string MvpNamespace = "mvp-xml"; public const string MvpPrefix = "mvp"; /// <summary> /// The resource name for sample data from a library (<see cref="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconXslTransformClassImplementsXSLTProcessor.asp?frame=true&hidetoc=true"/>. /// </summary> public const string LibraryResource = "Mvp.Xml.Tests.library.xml"; /// <summary> /// The resource name for sample data from Pubs database. /// </summary> public const string PubsResource = "Mvp.Xml.Tests.pubs.xml"; /// <summary> /// The resource name for sample data from Pubs database with xmlns="mvp-xml". /// </summary> public const string PubsNsResource = "Mvp.Xml.Tests.pubsNs.xml"; /// <summary> /// The resource name for schema for the resource <see cref="PubsNsResource"/>. /// </summary> public const string PubsNsSchemaResource = "Mvp.Xml.Tests.pubsNs.xsd"; /// <summary> /// The resource name for sample data from Pubs database. /// </summary> public const string NorthwindResource = "Mvp.Xml.Tests.northwind.xml"; public static Stream GetResource(string name) { return typeof(Globals).Assembly.GetManifestResourceStream( name); } } } --- NEW FILE: pubsNs.xsd --- <?xml version="1.0" ?> <xs:schema xmlns:tns="mvp-xml" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="mvp-xml" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="dsPubs"> <xs:complexType> <xs:sequence> <xs:element maxOccurs="unbounded" name="publishers"> <xs:complexType> <xs:sequence> <xs:element name="pub_id" type="xs:unsignedShort" /> <xs:element name="pub_name" type="xs:string" /> <xs:element name="city" type="xs:string" /> <xs:element minOccurs="0" name="state" type="xs:string" /> <xs:element name="country" type="xs:string" /> <xs:element minOccurs="0" maxOccurs="unbounded" name="titles"> <xs:complexType> <xs:sequence> <xs:element name="title_id" type="xs:string" /> <xs:element name="title" type="xs:string" /> <xs:element name="type" type="xs:string" /> <xs:element name="pub_id" type="xs:unsignedShort" /> <xs:element minOccurs="0" name="price" type="xs:decimal" /> <xs:element minOccurs="0" name="advance" type="xs:unsignedShort" /> <xs:element minOccurs="0" name="royalty" type="xs:unsignedByte" /> <xs:element minOccurs="0" name="ytd_sales" type="xs:unsignedShort" /> <xs:element minOccurs="0" name="notes" type="xs:string" /> <xs:element name="pubdate" type="xs:dateTime" /> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> <xs:attribute name="id" type="xs:string" /> </xs:complexType> </xs:element> </xs:schema> --- NEW FILE: changelog.txt --- --------------------------------------------------------- April 01, 2004 Initial setup. Folder should preferably contain NUnit tests. --- NEW FILE: XmlNodeListFactoryTests.cs --- #region using using System; using System.Collections; using System.IO; using System.Xml; using System.Xml.Serialization; using System.Xml.XPath; using NUnit.Framework; using Mvp.Xml.Common; #endregion using namespace Mvp.Xml.Tests { /// <summary> /// </summary> [TestFixture] public class XmlNodeListFactoryTests { private XmlDocument pubsDocument; [SetUp] public void Setup() { pubsDocument = new XmlDocument(); pubsDocument.Load(Globals.GetResource(Globals.PubsResource)); } [Test] public void MultipleCompleteEnumerations() { XPathNodeIterator nodeIterator = pubsDocument.CreateNavigator().Select("/dsPubs/publishers"); XmlNodeList nodeList = XmlNodeListFactory.CreateNodeList(nodeIterator); // Get the first node list enumerator. IEnumerator enumerator = nodeList.GetEnumerator(); while (enumerator.MoveNext()) { // Enumerate all publishers. } // Get the second node list enumerator. enumerator = nodeList.GetEnumerator(); // Ensure that the second node list enumerator is in a usable state. Assert.IsTrue(enumerator.MoveNext()); } [Test] public void List1() { string xml = @"<?xml version='1.0'?> <root> <element>1</element> <element></element> <element/> <element>2</element> </root>"; XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); XPathNodeIterator iterator = doc.CreateNavigator().Select("//element"); XmlNodeList list = XmlNodeListFactory.CreateNodeList(iterator); int count = 0; foreach (XmlNode n in list) { count++; } Assert.AreEqual(4, count); iterator = doc.CreateNavigator().Select("//element"); list = XmlNodeListFactory.CreateNodeList(iterator); Assert.AreEqual(4, list.Count); } } } --- NEW FILE: DebuggingXPathNavigator.cs --- using System; using System.Xml; using System.Xml.XPath; namespace Mvp.Xml.Tests { /// <summary> /// Allows tracking of what members of the /// <see cref="XPathNavigator"/> class are being called. /// </summary> public sealed class DebuggingXPathNavigator : XPathNavigator { XPathNavigator _navigator; public DebuggingXPathNavigator(XPathNavigator navigator) { _navigator = navigator; } #region XPathNavigator overrides #region Properties /// <summary> /// See <see cref="XPathNavigator.BaseURI"/>. /// </summary> public override String BaseURI { get { System.Diagnostics.Debug.WriteLine("BaseURI = " + _navigator.BaseURI); return _navigator.BaseURI; } } /// <summary> /// See <see cref="XPathNavigator.HasAttributes"/>. /// </summary> public override bool HasAttributes { get { System.Diagnostics.Debug.WriteLine("HasAttributes = " + _navigator.HasAttributes); return _navigator.HasAttributes; } } /// <summary> /// See <see cref="XPathNavigator.HasChildren"/>. /// </summary> public override bool HasChildren { get { System.Diagnostics.Debug.WriteLine("HasAttributes = " + _navigator.HasChildren); return _navigator.HasChildren; } } /// <summary> /// See <see cref="XPathNavigator.IsEmptyElement"/>. /// </summary> public override bool IsEmptyElement { get { System.Diagnostics.Debug.WriteLine("IsEmptyElement = " + _navigator.IsEmptyElement); return _navigator.IsEmptyElement; } } /// <summary> /// See <see cref="XPathNavigator.LocalName"/>. /// </summary> public override string LocalName { get { System.Diagnostics.Debug.WriteLine("LocalName = " + _navigator.LocalName); return _navigator.LocalName; } } /// <summary> /// See <see cref="XPathNavigator.Name"/>. /// </summary> public override string Name { get { System.Diagnostics.Debug.WriteLine("Name = " + _navigator.Name); return _navigator.Name; } } /// <summary> /// See <see cref="XPathNavigator.NamespaceURI"/>. /// </summary> public override string NamespaceURI { get { System.Diagnostics.Debug.WriteLine("NamespaceURI = " + _navigator.NamespaceURI); return _navigator.NamespaceURI; } } /// <summary> /// See <see cref="XPathNavigator.NameTable"/>. /// </summary> public override XmlNameTable NameTable { get { System.Diagnostics.Debug.WriteLine("NameTable = " + _navigator.NameTable); return _navigator.NameTable; } } /// <summary> /// See <see cref="XPathNavigator.NodeType"/>. /// </summary> public override XPathNodeType NodeType { get { System.Diagnostics.Debug.WriteLine("NodeType = " + _navigator.NodeType); return _navigator.NodeType; } } /// <summary> /// See <see cref="XPathNavigator.Prefix"/>. /// </summary> public override string Prefix { get { System.Diagnostics.Debug.WriteLine("Prefix = " + _navigator.Prefix); return _navigator.Prefix; } } /// <summary> /// See <see cref="XPathNavigator.Value"/>. /// </summary> public override string Value { get { System.Diagnostics.Debug.WriteLine("Value = " + _navigator.Value); return _navigator.Value; } } /// <summary> /// See <see cref="XPathNavigator.XmlLang"/>. /// </summary> public override string XmlLang { get { System.Diagnostics.Debug.WriteLine("XmlLang = " + _navigator.XmlLang); return _navigator.XmlLang; } } #endregion Properties #region Methods /// <summary> /// Creates new cloned version of the <see cref="SubtreeeXPathNavigator"/>. /// </summary> /// <returns>Cloned copy of the <see cref="SubtreeeXPathNavigator"/>.</returns> public override XPathNavigator Clone() { System.Diagnostics.Debug.WriteLine("Clone()"); return new DebuggingXPathNavigator(_navigator.Clone()); } /// <summary> /// See <see cref="XPathNavigator.IsSamePosition"/>. /// </summary> public override bool IsSamePosition(XPathNavigator other) { bool res = _navigator.IsSamePosition(other); System.Diagnostics.Debug.WriteLine("IsSamePosition(" + (other != null ? other.ToString() : "null") + ") = " + res); return res; } /// <summary> /// See <see cref="XPathNavigator.MoveToId"/>. /// </summary> public override bool MoveToId(string id) { bool res = _navigator.MoveToId(id); System.Diagnostics.Debug.WriteLine("MoveToId(" + id + ") = " + res); return res; } #region Element methods /// <summary> /// See <see cref="XPathNavigator.MoveTo"/>. /// </summary> public override bool MoveTo(XPathNavigator other) { bool res = _navigator.MoveTo(other); System.Diagnostics.Debug.WriteLine("MoveTo(" + (other != null ? other.ToString() : "null") + ") = " + res); return res; } /// <summary> /// See <see cref="XPathNavigator.MoveToFirst"/>. /// </summary> public override bool MoveToFirst() { bool res = _navigator.MoveToFirst(); System.Diagnostics.Debug.WriteLine("MoveToFirst() = " + res); return res; } /// <summary> /// See <see cref="XPathNavigator.MoveToFirstChild"/>. /// </summary> public override bool MoveToFirstChild() { bool res = _navigator.MoveToFirstChild(); System.Diagnostics.Debug.WriteLine("MoveToFirstChild() = " + res); return res; } /// <summary> /// See <see cref="XPathNavigator.MoveToNext"/>. /// </summary> public override bool MoveToNext() { bool res = _navigator.MoveToNext(); System.Diagnostics.Debug.WriteLine("MoveToNext() = " + res); return res; } /// <summary> /// See <see cref="XPathNavigator.MoveToParent"/>. /// </summary> public override bool MoveToParent() { bool res = _navigator.MoveToParent(); System.Diagnostics.Debug.WriteLine("MoveToParent() = " + res); return res; } /// <summary> /// See <see cref="XPathNavigator.MoveToPrevious"/>. /// </summary> public override bool MoveToPrevious() { bool res = _navigator.MoveToPrevious(); System.Diagnostics.Debug.WriteLine("MoveToPrevious() = " + res); return res; } /// <summary> /// See <see cref="XPathNavigator.MoveToRoot"/>. /// </summary> public override void MoveToRoot() { System.Diagnostics.Debug.WriteLine("MoveToRoot()"); _navigator.MoveToRoot(); } #endregion Element methods #region Attribute methods /// <summary> /// See <see cref="XPathNavigator.GetAttribute"/>. /// </summary> public override string GetAttribute(string localName, string namespaceURI) { string attr = _navigator.GetAttribute(localName, namespaceURI); System.Diagnostics.Debug.WriteLine("GetAttribute(" + localName + ", " + namespaceURI + ") = " + attr); return attr; } /// <summary> /// See <see cref="XPathNavigator.MoveToAttribute"/>. /// </summary> public override bool MoveToAttribute(string localName, string namespaceURI) { bool res = _navigator.MoveToAttribute(localName, namespaceURI); System.Diagnostics.Debug.WriteLine("MoveToAttribute(" + localName + ", " + namespaceURI + ") = " + res); return res; } /// <summary> /// See <see cref="XPathNavigator.MoveToFirstAttribute"/>. /// </summary> public override bool MoveToFirstAttribute() { bool res = _navigator.MoveToFirstAttribute(); System.Diagnostics.Debug.WriteLine("MoveToFirstAttribute() = " + res); return res; } /// <summary> /// See <see cref="XPathNavigator.MoveToNextAttribute"/>. /// </summary> public override bool MoveToNextAttribute() { bool res = _navigator.MoveToNextAttribute(); System.Diagnostics.Debug.WriteLine("MoveToNextAttribute() = " + res); return res; } #endregion Attribute methods #region Namespace methods /// <summary> /// See <see cref="XPathNavigator.GetNamespace"/>. /// </summary> public override string GetNamespace(string localName) { string attr = _navigator.GetNamespace(localName); System.Diagnostics.Debug.WriteLine("GetNamespace(" + localName + ") = " + attr); return attr; } /// <summary> /// See <see cref="XPathNavigator.MoveToNamespace"/>. /// </summary> public override bool MoveToNamespace(string @namespace) { bool res = _navigator.MoveToNamespace(@namespace); System.Diagnostics.Debug.WriteLine("MoveToNamespace(" + @namespace + ") = " + res); return res; } /// <summary> /// See <see cref="XPathNavigator.MoveToFirstNamespace"/>. /// </summary> public override bool MoveToFirstNamespace(XPathNamespaceScope namespaceScope) { bool res = _navigator.MoveToFirstNamespace(); System.Diagnostics.Debug.WriteLine("MoveToFirstNamespace() = " + res); return res; } /// <summary> /// See <see cref="XPathNavigator.MoveToNextNamespace"/>. /// </summary> public override bool MoveToNextNamespace(XPathNamespaceScope namespaceScope) { bool res = _navigator.MoveToNextNamespace(namespaceScope); System.Diagnostics.Debug.WriteLine("MoveToNextNamespace(" + namespaceScope + ") = " + res); return res; } #endregion Namespace methods #endregion Methods #endregion } } --- NEW FILE: library.xml --- <library> <book genre='novel' ISBN='1-861001-57-5'> <title>Pride And Prejudice</title> </book> <book genre='novel' ISBN='1-81920-21-2'> <title>Hook</title> </book> </library> --- NEW FILE: pubs.xml --- <?xml version="1.0" standalone="yes"?> <dsPubs id="123"> <publishers> <pub_id>0736</pub_id> <pub_name>New Moon Books</pub_name> <city>Boston</city> <state>MA</state> <country>USA</country> <titles xmlns:kzu="urn-kzu"> <kzu:test kzu:value="pepe">Data</kzu:test> <title_id>BU2075</title_id> <title>You Can Combat Computer Stress!</title> <type>business </type> <pub_id>0736</pub_id> <price>2.99</price> <advance>10125</advance> <royalty>24</royalty> <ytd_sales>18722</ytd_sales> <notes>The latest medical and psychological techniques for living with the electronic office. Easy-to-understand explanations.</notes> <pubdate>1991-06-30T00:00:00.0000000-03:00</pubdate> </titles> <titles> <title_id>PS2091</title_id> <title>Is Anger the Enemy?</title> <type>psychology </type> <pub_id>0736</pub_id> <price>10.95</price> <advance>2275</advance> <royalty>12</royalty> <ytd_sales>2045</ytd_sales> <notes>Carefully researched study of the effects of strong emotions on the body. Metabolic charts included.</notes> <pubdate>1991-06-15T00:00:00.0000000-03:00</pubdate> </titles> <titles> <title_id>PS2106</title_id> <title>Life Without Fear</title> <type>psychology </type> <pub_id>0736</pub_id> <price>7</price> <advance>6000</advance> <royalty>10</royalty> <ytd_sales>111</ytd_sales> <notes>New exercise, meditation, and nutritional techniques that can reduce the shock of daily interactions. Popular audience. Sample menus included, exercise video available separately.</notes> <pubdate>1991-10-05T00:00:00.0000000-03:00</pubdate> </titles> <titles> <title_id>PS3333</title_id> <title>Prolonged Data Deprivation: Four Case Studies</title> <type>psychology </type> <pub_id>0736</pub_id> <price>19.99</price> <advance>2000</advance> <royalty>10</royalty> <ytd_sales>4072</ytd_sales> <notes>What happens when the data runs dry? Searching evaluations of information-shortage effects.</notes> <pubdate>1991-06-12T00:00:00.0000000-03:00</pubdate> </titles> <titles> <title_id>PS7777</title_id> <title>Emotional Security: A New Algorithm</title> <type>psychology </type> <pub_id>0736</pub_id> <price>7.99</price> <advance>4000</advance> <royalty>10</royalty> <ytd_sales>3336</ytd_sales> <notes>Protecting yourself and your loved ones from undue emotional stress in the modern world. Use of computer and nutritional aids emphasized.</notes> <pubdate>1991-06-12T00:00:00.0000000-03:00</pubdate> </titles> </publishers> <publishers> <pub_id>0877</pub_id> <pub_name>Binnet & Hardley</pub_name> <city>Washington</city> <state>DC</state> <country>USA</country> <titles> <title_id>MC2222</title_id> <title>Silicon Valley Gastronomic Treats</title> <type>mod_cook </type> <pub_id>0877</pub_id> <price>19.99</price> <advance>0</advance> <royalty>12</royalty> <ytd_sales>2032</ytd_sales> <notes>Favorite recipes for quick, easy, and elegant meals.</notes> <pubdate>1991-06-09T00:00:00.0000000-03:00</pubdate> </titles> <titles> <title_id>MC3021</title_id> <title>The Gourmet Microwave</title> <type>mod_cook </type> <pub_id>0877</pub_id> <price>2.99</price> <advance>15000</advance> <royalty>24</royalty> <ytd_sales>22246</ytd_sales> <notes>Traditional French gourmet recipes adapted for modern microwave cooking.</notes> <pubdate>1991-06-18T00:00:00.0000000-03:00</pubdate> </titles> <titles> <title_id>MC3026</title_id> <title>The Psychology of Computer Cooking</title> <type>UNDECIDED </type> <pub_id>0877</pub_id> <pubdate>2000-08-06T00:00:00.0000000-03:00</pubdate> </titles> <titles> <title_id>PS1372</title_id> <title>Computer Phobic AND Non-Phobic Individuals: Behavior Variations</title> <type>psychology </type> <pub_id>0877</pub_id> <price>21.59</price> <advance>7000</advance> <royalty>10</royalty> <ytd_sales>375</ytd_sales> <notes>A must for the specialist, this book examines the difference between those who hate and fear computers and those who don't.</notes> <pubdate>1991-10-21T00:00:00.0000000-03:00</pubdate> </titles> <titles> <title_id>TC3218</title_id> <title>Onions, Leeks, and Garlic: Cooking Secrets of the Mediterranean</title> <type>trad_cook </type> <pub_id>0877</pub_id> <price>20.95</price> <advance>7000</advance> <royalty>10</royalty> <ytd_sales>375</ytd_sales> <notes>Profusely illustrated in color, this makes a wonderful gift book for a cuisine-oriented friend.</notes> <pubdate>1991-10-21T00:00:00.0000000-03:00</pubdate> </titles> <titles> <title_id>TC4203</title_id> <title>Fifty Years in Buckingham Palace Kitchens</title> <type>trad_cook </type> <pub_id>0877</pub_id> <price>11.95</price> <advance>4000</advance> <royalty>14</royalty> <ytd_sales>15096</ytd_sales> <notes>More anecdotes from the Queen's favorite cook describing life among English royalty. Recipes, techniques, tender vignettes.</notes> <pubdate>1991-06-12T00:00:00.0000000-03:00</pubdate> </titles> <titles> <title_id>TC7777</title_id> <title>Sushi, Anyone?</title> <type>trad_cook </type> <pub_id>0877</pub_id> <price>14.99</price> <advance>8000</advance> <royalty>10</royalty> <ytd_sales>4095</ytd_sales> <notes>Detailed instructions on how to make authentic Japanese sushi in your spare time.</notes> <pubdate>1991-06-12T00:00:00.0000000-03:00</pubdate> </titles> </publishers> <publishers> <pub_id>1389</pub_id> <pub_name>Algodata Infosystems</pub_name> <city>Berkeley</city> <state>CA</state> <country>USA</country> <titles> <title_id>BU1032</title_id> <title>The Busy Executive's Database Guide</title> <type>business </type> <pub_id>1389</pub_id> <price>19.99</price> <advance>5000</advance> <royalty>10</royalty> <ytd_sales>4095</ytd_sales> <notes>An overview of available database systems with emphasis on common business applications. Illustrated.</notes> <pubdate>1991-06-12T00:00:00.0000000-03:00</pubdate> </titles> <titles> <title_id>BU1111</title_id> <title>Cooking with Computers: Surreptitious Balance Sheets</title> <type>business </type> <pub_id>1389</pub_id> <price>11.95</price> <advance>5000</advance> <royalty>10</royalty> <ytd_sales>3876</ytd_sales> <notes>Helpful hints on how to use your electronic resources to the best advantage.</notes> <pubdate>1991-06-09T00:00:00.0000000-03:00</pubdate> </titles> <titles> <title_id>BU7832</title_id> <title>Straight Talk About Computers</title> <type>business </type> <pub_id>1389</pub_id> <price>19.99</price> <advance>5000</advance> <royalty>10</royalty> <ytd_sales>4095</ytd_sales> <notes>Annotated analysis of what computers can do for you: a no-hype guide for the critical user.</notes> <pubdate>1991-06-22T00:00:00.0000000-03:00</pubdate> </titles> <titles> <title_id>PC1035</title_id> <title>But Is It User Friendly?</title> <type>popular_comp</type> <pub_id>1389</pub_id> <price>22.95</price> <advance>7000</advance> <royalty>16</royalty> <ytd_sales>8780</ytd_sales> <notes>A survey of software for the naive user, focusing on the 'friendliness' of each.</notes> <pubdate>1991-06-30T00:00:00.0000000-03:00</pubdate> </titles> <titles> <title_id>PC8888</title_id> <title>Secrets of Silicon Valley</title> <type>popular_comp</type> <pub_id>1389</pub_id> <price>20</price> <advance>8000</advance> <royalty>10</royalty> <ytd_sales>4095</ytd_sales> <notes>Muckraking reporting on the world's largest computer hardware and software manufacturers.</notes> <pubdate>1994-06-12T00:00:00.0000000-03:00</pubdate> </titles> <titles> <title_id>PC9999</title_id> <title>Net Etiquette</title> <type>popular_comp</type> <pub_id>1389</pub_id> <notes>A must-read for computer conferencing.</notes> <pubdate>2000-08-06T00:00:00.0000000-03:00</pubdate> </titles> </publishers> <publishers> <pub_id>1622</pub_id> <pub_name>Five Lakes Publishing</pub_name> <city>Chicago</city> <state>IL</state> <country>USA</country> </publishers> <publishers> <pub_id>1756</pub_id> <pub_name>Ramona Publishers</pub_name> <city>Dallas</city> <state>TX</state> <country>USA</country> </publishers> <publishers> <pub_id>9901</pub_id> <pub_name>GGG&G</pub_name> <city>München</city> <country>Germany</country> </publishers> <publishers> <pub_id>9952</pub_id> <pub_name>Scootney Books</pub_name> <city>New York</city> <state>NY</state> <country>USA</country> </publishers> <publishers> <pub_id>9999</pub_id> <pub_name>Lucerne Publishing</pub_name> <city>Paris</city> <country>France</country> </publishers> </dsPubs> --- NEW FILE: pubsNs.xml --- <?xml version="1.0" standalone="yes"?> <dsPubs id="123" xmlns="mvp-xml"> <publishers> <pub_id>0736</pub_id> <pub_name>New Moon Books</pub_name> <city>Boston</city> <state>MA</state> <country>USA</country> <titles> <title_id>BU2075</title_id> <title>You Can Combat Computer Stress!</title> <type>business </type> <pub_id>0736</pub_id> <price>2.99</price> <advance>10125</advance> <royalty>24</royalty> <ytd_sales>18722</ytd_sales> <notes>The latest medical and psychological techniques for living with the electronic office. Easy-to-understand explanations.</notes> <pubdate>1991-06-30T00:00:00.0000000-03:00</pubdate> [...1193 lines suppressed...] <pub_id>1389</pub_id> <notes>A must-read for computer conferencing.</notes> <pubdate>2000-08-06T00:00:00.0000000-03:00</pubdate> </titles> </publishers> <publishers> <pub_id>1622</pub_id> <pub_name>Five Lakes Publishing</pub_name> <city>Chicago</city> <state>IL</state> <country>USA</country> </publishers> <publishers> <pub_id>1756</pub_id> <pub_name>Ramona Publishers</pub_name> <city>Dallas</city> <state>TX</state> <country>USA</country> </publishers> </dsPubs> --- NEW FILE: northwind.xml --- <?xml version="1.0" encoding="windows-1252"?> <ROOT> <CustomerIDs> <CustomerID> ALFKI</CustomerID> <CompanyName> Alfreds Futterkiste</CompanyName> <ContactName> Maria Anders</ContactName> <OrderIDs> <Item> <OrderID> 10952</OrderID> <OrderDate> 4/15/96</OrderDate> <ShipAddress> Obere Str. 57</ShipAddress> </Item> <Item> <OrderID> 10643</OrderID> <OrderDate> 9/25/95</OrderDate> <ShipAddress> Obere Str. 57</ShipAddress> </Item> <Item> <OrderID> 10702</OrderID> [...4607 lines suppressed...] <ShipAddress> ul. Filtrowa 68</ShipAddress> </Item> <Item> <OrderID> 10870</OrderID> <OrderDate> 3/6/96</OrderDate> <ShipAddress> ul. Filtrowa 68</ShipAddress> </Item> <Item> <OrderID> 10611</OrderID> <OrderDate> 8/25/95</OrderDate> <ShipAddress> ul. Filtrowa 68</ShipAddress> </Item> <Item> <OrderID> 11044</OrderID> <OrderDate> 5/23/96</OrderDate> <ShipAddress> ul. Filtrowa 68</ShipAddress> </Item> </OrderIDs> </CustomerIDs> </ROOT> --- NEW FILE: XmlNodeFactoryTests.cs --- #region using using System; using System.IO; using System.Xml; using System.Xml.Serialization; using System.Xml.XPath; using NUnit.Framework; using Mvp.Xml.Common; #endregion using namespace Mvp.Xml.Tests { /// <summary> /// </summary> [TestFixture] public class XmlNodeFactoryTests { static XmlSerializer ser = new XmlSerializer(typeof(XmlNode)); [Test] public void NodeFromReader() { string xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><root><element>1</element><element></element><element>2</element></root>"; XmlTextReader tr = new XmlTextReader(new StringReader(xml)); XmlNode node = XmlNodeFactory.Create(tr); MemoryStream mem = new MemoryStream(); XmlTextWriter tw = new XmlTextWriter(mem, System.Text.Encoding.UTF8); tw.Formatting = Formatting.None; ser.Serialize(tw, node); mem.Position = 0; string res = new StreamReader(mem).ReadToEnd(); Assert.AreEqual(xml, res); } [Test] public void NodeFromNavigator() { string xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><root><element>1</element><element /><element>2</element></root>"; XPathDocument doc = new XPathDocument(new StringReader(xml)); XPathNavigator nav = doc.CreateNavigator(); XmlNode node = XmlNodeFactory.Create(nav); MemoryStream mem = new MemoryStream(); XmlTextWriter tw = new XmlTextWriter(mem, System.Text.Encoding.UTF8); tw.Formatting = Formatting.None; ser.Serialize(tw, node); mem.Position = 0; string res = new StreamReader(mem).ReadToEnd(); Assert.AreEqual(xml, res); nav.MoveToRoot(); nav.MoveToFirstChild(); nav.MoveToFirstChild(); node = XmlNodeFactory.Create(nav); mem = new MemoryStream(); tw = new XmlTextWriter(mem, System.Text.Encoding.UTF8); tw.Formatting = Formatting.None; ser.Serialize(tw, node); mem.Position = 0; res = new StreamReader(mem).ReadToEnd(); Assert.AreEqual("<?xml version=\"1.0\" encoding=\"utf-8\"?><element>1</element>", res); } [Test] public void NodeFromObject() { Customer cust = new Customer(); cust.FirstName = "Daniel"; cust.LastName = "Cazzulino"; XmlNode node = XmlNodeFactory.Create(cust); MemoryStream mem = new MemoryStream(); XmlTextWriter tw = new XmlTextWriter(mem, System.Text.Encoding.UTF8); tw.Formatting = Formatting.None; ser.Serialize(tw, node); mem.Position = 0; XmlSerializer customerSerializer = new XmlSerializer(typeof(Customer)); Customer result = (Customer) customerSerializer.Deserialize(mem); Assert.AreEqual(cust.FirstName, result.FirstName); Assert.AreEqual(cust.LastName, result.LastName); Assert.AreEqual(cust.BirthDate, result.BirthDate); } public class Customer { public string FirstName; public string LastName; public DateTime BirthDate; } } } --- NEW FILE: XPathCacheUsability.cs --- using System; using System.Xml; using System.Xml.XPath; using Mvp.Xml.Common.XPath; namespace Mvp.Xml.Tests { public class XPathCacheUsability { /// <summary> /// This code is just to show how it's used. /// If run it will throw exceptions. /// </summary> public void Test() { XPathNavigator document = new XPathDocument(String.Empty).CreateNavigator(); XPathNodeIterator it = XPathCache.Select("/customer/order/item", document); it = XPathCache.Select("/customer/order[id=$id]/item", document, new XPathVariable("id", "23")); string[] ids = null; foreach (string id in ids) { it = XPathCache.Select("/customer/order[id=$id]/item", document, new XPathVariable("id", id)); } XmlNamespaceManager mgr = new XmlNamespaceManager(document.NameTable); mgr.AddNamespace("po", "example-po"); it = XPathCache.Select("/po:customer[id=$id]", document, mgr, new XPathVariable("id", "0736")); XmlDocument doc = new XmlDocument(); XmlNodeList list = XPathCache.SelectNodes("/customer", doc); } } } --- NEW FILE: Misc.cs --- using System; using System.Collections; using System.Diagnostics; using System.IO; using System.Reflection; using System.Xml; using System.Xml.Serialization; using System.Xml.XPath; using System.Xml.Schema; using NUnit.Framework; namespace Mvp.Xml.Tests { /// <summary> /// Miscelaneous tests. /// </summary> [TestFixture] public class Misc { [Test] public void SerializeXmlDocument() { XmlSerializer ser = new XmlSerializer(typeof(XmlDocument)); int j = 3; double k = (double) j ; short s = 1; double ds = (double) s; Assert.IsNotNull(ser); } [Test] public void CursorMovement() { XPathDocument doc = new XPathDocument(Globals.GetResource(Globals.NorthwindResource)); XPathNavigator nav = doc.CreateNavigator(); nav.MoveToFirstChild(); nav.MoveToFirstChild(); XPathNavigator prev = nav.Clone(); XPathNodeIterator it = nav.Select("//CustomerID"); Assert.IsTrue(nav.IsSamePosition(prev)); } } } --- NEW FILE: XPathSortBug.cs --- using System; using System.IO; using System.Xml; using System.Xml.XPath; using NUnit.Framework; namespace Mvp.Xml.Tests { /// <summary/> [TestFixture] public class XPathSortBug { [Test] public void Repro() { string xml = @" <root xmlns='mvp-xml'> <item> <value>25</value> </item> <item> <value>40</value> </item> <item> <value>10</value> </item> </root>"; XPathDocument doc = new XPathDocument(new StringReader(xml)); XPathNavigator nav = doc.CreateNavigator(); // Setup namespace resolution. XmlNamespaceManager ctx = new XmlNamespaceManager(nav.NameTable); ctx.AddNamespace("mvp", "mvp-xml"); // Create sort expression. XPathExpression sort = nav.Compile("mvp:value"); sort.SetContext(ctx); // Setting the sort *after* the context yields no results at all. XPathExpression items = nav.Compile("//mvp:item"); items.AddSort(sort, XmlSortOrder.Ascending, XmlCaseOrder.None, String.Empty, XmlDataType.Number); items.SetContext(ctx); XPathNodeIterator it = doc.CreateNavigator().Select(items); Assert.IsFalse( it.MoveNext() ); // The same code but setting the sort *after* the context works fine. items = nav.Compile("//mvp:item"); items.SetContext(ctx); items.AddSort(sort, XmlSortOrder.Ascending, XmlCaseOrder.None, String.Empty, XmlDataType.Number); it = doc.CreateNavigator().Select(items); Assert.IsTrue( it.MoveNext() ); } } } --- NEW FILE: DebuggingXmlTextReader.cs --- #region using using System; using System.IO; using System.Xml; #endregion using namespace Mvp.Xml.Tests { internal class DebuggingXmlTextReader : XmlTextReader { XmlReader _reader; public DebuggingXmlTextReader(Stream input) : base(new StringReader(String.Empty)) { _reader = new XmlTextReader(input); } public DebuggingXmlTextReader(TextReader input) : base(new StringReader(String.Empty)) { _reader = new XmlTextReader(input); } public DebuggingXmlTextReader(XmlReader input) : base(new StringReader(String.Empty)) { _reader = input; } public override int AttributeCount { get { System.Diagnostics.Debug.WriteLine("AttributeCount = " + _reader.AttributeCount); return _reader.AttributeCount; } } public override string BaseURI { get { System.Diagnostics.Debug.WriteLine("BaseURI = " + _reader.BaseURI); return _reader.BaseURI; } } public override bool CanResolveEntity { get { System.Diagnostics.Debug.WriteLine("CanResolveEntity = " + _reader.CanResolveEntity); return _reader.CanResolveEntity; } } public override void Close() { System.Diagnostics.Debug.WriteLine("Close"); _reader.Close(); } public override int Depth { get { System.Diagnostics.Debug.WriteLine("Depth = " + _reader.Depth); return _reader.Depth; } } public override bool EOF { get { System.Diagnostics.Debug.WriteLine("EOF = " + _reader.EOF); return _reader.EOF; } } public override string GetAttribute(int i) { System.Diagnostics.Debug.WriteLine("GetAttribute(" + i + ")"); return _reader.GetAttribute(i); } public override string GetAttribute(string name) { System.Diagnostics.Debug.WriteLine("GetAttribute(" + name + ")"); return _reader.GetAttribute(name); } public override string GetAttribute(string name, string namespaceURI) { System.Diagnostics.Debug.WriteLine("GetAttribute(" + name + "), " + namespaceURI + ")"); return _reader.GetAttribute(name, namespaceURI); } public override bool HasAttributes { get { System.Diagnostics.Debug.WriteLine("HasAttributes = " + _reader.HasAttributes); return _reader.HasAttributes; } } public override bool HasValue { get { System.Diagnostics.Debug.WriteLine("HasValue = " + _reader.HasValue); return _reader.HasValue; } } public override bool IsDefault { get { System.Diagnostics.Debug.WriteLine("IsDefault = " + _reader.IsDefault); return _reader.IsDefault; } } public override bool IsEmptyElement { get { System.Diagnostics.Debug.WriteLine("IsEmptyElement = " + _reader.IsEmptyElement); return _reader.IsEmptyElement; } } public override bool IsStartElement() { System.Diagnostics.Debug.WriteLine("IsStartElement()"); return _reader.IsStartElement (); } public override bool IsStartElement(string localname, string ns) { System.Diagnostics.Debug.WriteLine("IsStartElement(" + localname + ", " + ns + ")"); return _reader.IsStartElement (localname, ns); } public override bool IsStartElement(string name) { System.Diagnostics.Debug.WriteLine("IsStartElement(" + name + ")"); return _reader.IsStartElement (name); } public override string LocalName { get { System.Diagnostics.Debug.WriteLine("LocalName = " + _reader.LocalName); return _reader.LocalName; } } public override string LookupNamespace(string prefix) { System.Diagnostics.Debug.WriteLine("LookupNamespace(" + prefix + ")"); return _reader.Prefix; } public override void MoveToAttribute(int i) { System.Diagnostics.Debug.WriteLine("MoveToAttribute(" + i + ")"); _reader.MoveToAttribute(i); } public override bool MoveToAttribute(string name) { System.Diagnostics.Debug.WriteLine("MoveToAttribute(" + name + ")"); return _reader.MoveToAttribute(name); } public override bool MoveToAttribute(string name, string ns) { System.Diagnostics.Debug.WriteLine("MoveToAttribute(" + name + ", " + ns + ")"); return _reader.MoveToAttribute(name, ns); } public override XmlNodeType MoveToContent() { System.Diagnostics.Debug.WriteLine("MoveToContent()"); return _reader.MoveToContent(); } public override bool MoveToElement() { System.Diagnostics.Debug.WriteLine("MoveToElement()"); return _reader.MoveToElement(); } public override bool MoveToFirstAttribute() { System.Diagnostics.Debug.WriteLine("MoveToFirstAttribute()"); return _reader.MoveToFirstAttribute(); } public override bool MoveToNextAttribute() { System.Diagnostics.Debug.WriteLine("MoveToNextAttribute()"); return _reader.MoveToNextAttribute(); } public override string Name { get { System.Diagnostics.Debug.WriteLine("Name = " + _reader.Name); return _reader.Name; } } public override string NamespaceURI { get { System.Diagnostics.Debug.WriteLine("NamespaceURI = " + _reader.NamespaceURI); return _reader.NamespaceURI; } } public override XmlNameTable NameTable { get { System.Diagnostics.Debug.WriteLine("NameTable"); return _reader.NameTable; } } public override XmlNodeType NodeType { get { System.Diagnostics.Debug.WriteLine("NodeType = " + _reader.NodeType); return _reader.NodeType; } } public override string Prefix { get { System.Diagnostics.Debug.WriteLine("Prefix = " + _reader.Prefix); return _reader.Prefix; } } public override char QuoteChar { get { System.Diagnostics.Debug.WriteLine("QuoteChar = " + _reader.QuoteChar); return _reader.QuoteChar; } } public override bool Read() { System.Diagnostics.Debug.WriteLine("Read()"); return _reader.Read(); } public override bool ReadAttributeValue() { System.Diagnostics.Debug.WriteLine("ReadAttributeValue()"); return _reader.ReadAttributeValue(); } public override string ReadElementString() { System.Diagnostics.Debug.WriteLine("ReadElementString()"); return _reader.ReadElementString(); } public override string ReadElementString(string localname, string ns) { System.Diagnostics.Debug.WriteLine("ReadElementString(" + localname + ", " + ns + ")"); return _reader.ReadElementString(localname, ns); } public override string ReadElementString(string name) { System.Diagnostics.Debug.WriteLine("ReadElementString(" + name + ")"); return _reader.ReadElementString(name); } public override void ReadEndElement() { System.Diagnostics.Debug.WriteLine("ReadEndElement()"); _reader.ReadEndElement(); } public override string ReadInnerXml() { System.Diagnostics.Debug.WriteLine("ReadInnerXml()"); return _reader.ReadInnerXml(); } public override string ReadOuterXml() { System.Diagnostics.Debug.WriteLine("ReadOuterXml()"); return _reader.ReadOuterXml(); } public override void ReadStartElement() { System.Diagnostics.Debug.WriteLine("ReadStartElement()"); _reader.ReadStartElement(); } public override void ReadStartElement(string localname, string ns) { System.Diagnostics.Debug.WriteLine("ReadStartElement(" + localname + ", " + ns + ")"); _reader.ReadStartElement(localname, ns); } public override void ReadStartElement(string name) { System.Diagnostics.Debug.WriteLine("ReadStartElement(" + name + ")"); _reader.ReadStartElement(name); } public override ReadState ReadState { get { System.Diagnostics.Debug.WriteLine("ReadState = " + _reader.ReadState); return _reader.ReadState; } } public override string ReadString() { System.Diagnostics.Debug.WriteLine("ReadString()"); return _reader.ReadString(); } public override void ResolveEntity() { System.Diagnostics.Debug.WriteLine("ResolveEntity()"); _reader.ResolveEntity(); } public override void Skip() { System.Diagnostics.Debug.WriteLine("Skip()"); _reader.Skip(); } public override string this[int i] { get { System.Diagnostics.Debug.WriteLine("this[" + i + "]"); return base[i]; } } public override string this[string name, string namespaceURI] { get { System.Diagnostics.Debug.WriteLine("this[" + name + ", " + namespaceURI + "]"); return base[name, namespaceURI]; } } public override string this[string name] { get { System.Diagnostics.Debug.WriteLine("this[" + name + "]"); return base[name]; } } public override string Value { get { System.Diagnostics.Debug.WriteLine("Value = " + _reader.Value); return _reader.Value; } } public override string XmlLang { get { System.Diagnostics.Debug.WriteLine("XmlLang = " + _reader.XmlLang); return _reader.XmlLang; } } public override XmlSpace XmlSpace { get { System.Diagnostics.Debug.WriteLine("XmlSpace = " + _reader.XmlSpace); return _reader.XmlSpace; } } } } --- NEW FILE: pubsNs.cs --- namespace Mvp.Xml.Tests { /// <remarks/> [System.Xml.Serialization.XmlTypeAttribute(Namespace="mvp-xml")] [System.Xml.Serialization.XmlRootAttribute(Namespace="mvp-xml", IsNullable=false)] public class dsPubs { /// <remarks/> [System.Xml.Serialization.XmlElementAttribute("publishers")] public dsPubsPublishers[] publishers; /// <remarks/> [System.Xml.Serialization.XmlAttributeAttribute()] public string id; } /// <remarks/> [System.Xml.Serialization.XmlTypeAttribute(Namespace="mvp-xml")] public class dsPubsPublishers { /// <remarks/> public System.UInt16 pub_id; /// <remarks/> public string pub_name; /// <remarks/> public string city; /// <remarks/> public string state; /// <remarks/> public string country; /// <remarks/> [System.Xml.Serialization.XmlElementAttribute("titles")] public dsPubsPublishersTitles[] titles; } /// <remarks/> [System.Xml.Serialization.XmlTypeAttribute(Namespace="mvp-xml")] public class dsPubsPublishersTitles { /// <remarks/> public string title_id; /// <remarks/> public string title; /// <remarks/> public string type; /// <remarks/> public System.UInt16 pub_id; /// <remarks/> public System.Decimal price; /// <remarks/> [System.Xml.Serialization.XmlIgnoreAttribute()] public bool priceSpecified; /// <remarks/> public System.UInt16 advance; /// <remarks/> [System.Xml.Serialization.XmlIgnoreAttribute()] public bool advanceSpecified; /// <remarks/> public System.Byte royalty; /// <remarks/> [System.Xml.Serialization.XmlIgnoreAttribute()] public bool royaltySpecified; /// <remarks/> public System.UInt16 ytd_sales; /// <remarks/> [System.Xml.Serialization.XmlIgnoreAttribute()] public bool ytd_salesSpecified; /// <remarks/> public string notes; /// <remarks/> public System.DateTime pubdate; } } --- NEW FILE: AssemblyInfo.cs --- using System.Reflection; using System.Runtime.CompilerServices; // // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. // [assembly: AssemblyTitle("")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("")] [assembly: AssemblyCopyright("")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // // Version information for an assembly consists of the following four values: // // Major Version // Minor Version // Build Number // Revision // // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: [assembly: AssemblyVersion("1.0.*")] // // In order to sign your assembly you must specify a key to use. Refer to the // Microsoft .NET Framework documentation for more information on assembly signing. // // Use the attributes below to control which key is used for signing. // // Notes: // (*) If no key is specified, the assembly is not signed. // (*) KeyName refers to a key that has been installed in the Crypto Service // Provider (CSP) on your machine. KeyFile refers to a file which contains // a key. // (*) If the KeyFile and the KeyName values are both specified, the // following processing occurs: // (1) If the KeyName can be found in the CSP, that key is used. // (2) If the KeyName does not exist and the KeyFile does exist, the key // in the KeyFile is installed into the CSP and used. // (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. // When specifying the KeyFile, the location of the KeyFile should be // relative to the project output directory which is // %Project Directory%\obj\<configuration>. For example, if your KeyFile is // located in the project directory, you would specify the AssemblyKeyFile // attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")] // (*) Delay Signing is an advanced option - see the Microsoft .NET Framework // documentation for more information on this. // [assembly: AssemblyDelaySign(false)] [assembly: AssemblyKeyFile("")] [assembly: AssemblyKeyName("")] --- NEW FILE: XPathCacheTests.cs --- using System; using System.Xml; using System.Xml.XPath; using Mvp.Xml.Common; using Mvp.Xml.Common.XPath; using NUnit.Framework; namespace Mvp.Xml.Tests { [TestFixture] public class XPathCacheTests { private XPathDocument Document; private XPathDocument DocumentNoNs; [SetUp] public void Setup() { Document = new XPathDocument(Globals.GetResource(Globals.PubsNsResource)); DocumentNoNs = new XPathDocument(Globals.GetResource(Globals.PubsResource)); } [TearDown] public void TearDown() { Document = null; } [Test] public void DefaultNamespace() { dsPubs pubs = new dsPubs(); pubs.id = "0736"; System.Xml.Serialization.XmlSerializer ser = new System.Xml.Serialization.XmlSerializer(typeof(dsPubs), String.Empty); System.IO.StringWriter sw = new System.IO.StringWriter(); ser.Serialize( sw, pubs ); string xml = sw.ToString(); Assert.IsNotNull(xml); } [Test] public void DynamicVariable() { string expr = "//mvp:titles[mvp:price > 10]"; string dyn = "//mvp:titles[mvp:price > $price]"; int price = 10; XPathNavigator docnav = Document.CreateNavigator(); XPathExpression xpath = docnav.Compile(expr); XmlNamespaceManager mgr = new XmlNamespaceManager(docnav.NameTable); mgr.AddNamespace(Globals.MvpPrefix, Globals.MvpNamespace); xpath.SetContext(mgr); int count1 = Document.CreateNavigator().Select(xpath).Count; // Test with compiled expression. int count2 = XPathCache.Select(expr, Document.CreateNavigator(), mgr).Count; Assert.AreEqual(count1, count2); // Test with dynamic expression. count2 = XPathCache.Select(dyn, Document.CreateNavigator(), mgr, new XPathVariable("price", price)).Count; Assert.AreEqual(count1, count2); } [Test] public void PrefixMapping() { string expr = "//mvp:titles[mvp:price > 10]"; XPathNavigator docnav = Document.CreateNavigator(); XPathExpression xpath = docnav.Compile(expr); XmlNamespaceManager mgr = new XmlNamespaceManager(docnav.NameTable); mgr.AddNamespace(Globals.MvpPrefix, Globals.MvpNamespace); xpath.SetContext(mgr); int count1 = Document.CreateNavigator().Select(xpath).Count; int count2 = XPathCache.Select(expr, Document.CreateNavigator(), new XmlPrefix(Globals.MvpPrefix, Globals.MvpNamespace, Document.CreateNavigator().NameTable)).Count; Assert.AreEqual(count1, count2); } [Test] public void Sorted1() { string expr = "//mvp:titles"; XPathNavigator docnav = Document.CreateNavigator(); XPathExpression xpath = docnav.Compile(expr); XmlNamespaceManager mgr = new XmlNamespaceManager(docnav.NameTable); mgr.AddNamespace(Globals.MvpPrefix, Globals.MvpNamespace); xpath.SetContext(mgr); XPathExpression sort = docnav.Compile("mvp:price"); sort.SetContext(mgr); xpath.AddSort(sort, XmlSortOrder.Ascending, XmlCaseOrder.LowerFirst, String.Empty, XmlDataType.Number); XPathNodeIterator it = Document.CreateNavigator().Select(xpath); DebugUtils.XPathNodeIteratorToConsole(it); it = Document.CreateNavigator().Select(xpath); it.MoveNext(); it.Current.MoveToFirstChild(); string id1 = it.Current.Value; XPathNodeIterator cached = XPathCache.SelectSorted( expr, Document.CreateNavigator(), "mvp:price", XmlSortOrder.Ascending, XmlCaseOrder.LowerFirst, String.Empty, XmlDataType.Number, new XmlPrefix(Globals.MvpPrefix, Globals.MvpNamespace, Document.CreateNavigator().NameTable)); DebugUtils.XPathNodeIteratorToConsole(cached); cached = XPathCache.SelectSorted( expr, Document.CreateNavigator(), "mvp:price", XmlSortOrder.Ascending, XmlCaseOrder.LowerFirst, String.Empty, XmlDataType.Number, new XmlPrefix(Globals.MvpPrefix, Globals.MvpNamespace, Document.CreateNavigator().NameTable)); cached.MoveNext(); cached.Current.MoveToFirstChild(); string id2 = cached.Current.Value; Assert.AreEqual(id1, id2); } } } --- NEW FILE: IndexingXPathNavigatorTest.cs --- using System; using System.Xml; using System.Xml.XPath; using System.Diagnostics; using Mvp.Xml.Common.XPath; using NUnit.Framework; namespace Mvp.Xml.Tests { /// <summary> /// Test class for IndexingXPathNavigator /// </summary> [TestFixture] public class IndexingXPathNavigatorTest { [Test] public void RunTests() { Main(new string[0]); } [STAThread] static void Main(string[] args) { Stopwatch stopWatch = new Stopwatch(); int repeat = 1000; stopWatch.Start(); XPathDocument doc = new XPathDocument(Globals.GetResource(Globals.NorthwindResource)); //XmlDocument doc = new XmlDocument(); //doc.Load("test/northwind.xml"); stopWatch.Stop(); Console.WriteLine("Loading XML document: {0, 6:f2} ms", stopWatch.ElapsedMilliseconds); XPathNavigator nav = doc.CreateNavigator(); XPathExpression expr = nav.Compile("/ROOT/CustomerIDs/OrderIDs/Item[OrderID=' 10330']/ShipAddress"); Console.WriteLine("Regular selection, warming..."); SelectNodes(nav, repeat, stopWatch, expr); Console.WriteLine("Regular selection, testing..."); SelectNodes(nav, repeat, stopWatch, expr); stopWatch.Start(); IndexingXPathNavigator inav = new IndexingXPathNavigator( doc.CreateNavigator()); stopWatch.Stop(); Console.WriteLine("Building IndexingXPathNavigator: {0, 6:f2} ms", stopWatch.ElapsedMilliseconds); stopWatch.Start(); inav.AddKey("orderKey", "OrderIDs/Item", "OrderID"); stopWatch.Stop(); Console.WriteLine("Adding keys: {0, 6:f2} ms", stopWatch.ElapsedMilliseconds); XPathExpression expr2 = inav.Compile("key('orderKey', ' 10330')/ShipAddress"); stopWatch.Start(); inav.BuildIndexes(); stopWatch.Stop(); Console.WriteLine("Indexing: {0, 6:f2} ms", stopWatch.ElapsedMilliseconds); Console.WriteLine("Indexed selection, warming..."); SelectIndexedNodes(inav, repeat, stopWatch, expr2); Console.WriteLine("Indexed selection, testing..."); SelectIndexedNodes(inav, repeat, stopWatch, expr2); } private static void SelectNodes(XPathNavigator nav, int repeat, Stopwatch stopWatch, XPathExpression expr) { int counter = 0; stopWatch.Start(); for (int i=0; i<repeat; i++) { XPathNodeIterator ni = nav.Select(expr); while (ni.MoveNext()) counter++; } stopWatch.Stop(); Console.WriteLine("Regular selection: {0} times, total time {1, 6:f2} ms, {2} nodes selected", repeat, stopWatch.ElapsedMilliseconds, counter); } private static void SelectIndexedNodes(XPathNavigator nav, int repeat, Stopwatch stopWatch, XPathExpression expr) { int counter = 0; stopWatch.Start(); for (int i=0; i<repeat; i++) { XPathNodeIterator ni = nav.Select(expr); while (ni.MoveNext()) counter++; } stopWatch.Stop(); Console.WriteLine("Indexed selection: {0} times, total time {1, 6:f2} ms, {2} nodes selected", repeat, stopWatch.ElapsedMilliseconds, counter); } } } |