XPathNavigatorReaderTests.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. //
  2. // MonoTests.System.Xml.XPathNavigatorReaderTests
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. // Copyright (C) 2005 Novell, Inc. http://www.novell.com
  8. //
  9. #if NET_2_0
  10. using System;
  11. using System.Xml;
  12. using System.Xml.XPath;
  13. using NUnit.Framework;
  14. using MonoTests.System.Xml; // XmlAssert
  15. namespace MonoTests.System.Xml.XPath
  16. {
  17. [TestFixture]
  18. public class XPathNavigatorReaderTests
  19. {
  20. XmlDocument document;
  21. XPathNavigator nav;
  22. XPathDocument xpathDocument;
  23. [SetUp]
  24. public void GetReady ()
  25. {
  26. document = new XmlDocument ();
  27. }
  28. private XPathNavigator GetXmlDocumentNavigator (string xml)
  29. {
  30. document.LoadXml (xml);
  31. return document.CreateNavigator ();
  32. }
  33. private XPathNavigator GetXPathDocumentNavigator (XmlNode node)
  34. {
  35. XmlNodeReader xr = new XmlNodeReader (node);
  36. xpathDocument = new XPathDocument (xr);
  37. return xpathDocument.CreateNavigator ();
  38. }
  39. [Test]
  40. public void ReadSubtree1 ()
  41. {
  42. string xml = "<root/>";
  43. nav = GetXmlDocumentNavigator (xml);
  44. ReadSubtree1 (nav, "#1.");
  45. nav.MoveToRoot ();
  46. nav.MoveToFirstChild ();
  47. ReadSubtree1 (nav, "#2.");
  48. nav = GetXPathDocumentNavigator (document);
  49. ReadSubtree1 (nav, "#3.");
  50. nav.MoveToRoot ();
  51. nav.MoveToFirstChild ();
  52. ReadSubtree1 (nav, "#4.");
  53. }
  54. void ReadSubtree1 (XPathNavigator nav, string label)
  55. {
  56. XmlReader r = nav.ReadSubtree ();
  57. XmlAssert.AssertNode (label + "#1", r,
  58. // NodeType, Depth, IsEmptyElement
  59. XmlNodeType.None, 0, false,
  60. // Name, Prefix, LocalName, NamespaceURI
  61. String.Empty, String.Empty, String.Empty, String.Empty,
  62. // Value, HasValue, AttributeCount, HasAttributes
  63. String.Empty, false, 0, false);
  64. Assert.IsTrue (r.Read (), label + "#2");
  65. XmlAssert.AssertNode (label + "#3", r,
  66. // NodeType, Depth, IsEmptyElement
  67. XmlNodeType.Element, 0, true,
  68. // Name, Prefix, LocalName, NamespaceURI
  69. "root", String.Empty, "root", String.Empty,
  70. // Value, HasValue, AttributeCount, HasAttributes
  71. String.Empty, false, 0, false);
  72. Assert.IsFalse (r.Read (), label + "#4");
  73. }
  74. [Test]
  75. public void ReadSubtree2 ()
  76. {
  77. string xml = "<root></root>";
  78. nav = GetXmlDocumentNavigator (xml);
  79. ReadSubtree2 (nav, "#1.");
  80. nav.MoveToRoot ();
  81. nav.MoveToFirstChild ();
  82. ReadSubtree2 (nav, "#2.");
  83. nav = GetXPathDocumentNavigator (document);
  84. ReadSubtree2 (nav, "#3.");
  85. nav.MoveToRoot ();
  86. nav.MoveToFirstChild ();
  87. ReadSubtree2 (nav, "#4.");
  88. }
  89. void ReadSubtree2 (XPathNavigator nav, string label)
  90. {
  91. XmlReader r = nav.ReadSubtree ();
  92. XmlAssert.AssertNode (label + "#1", r,
  93. // NodeType, Depth, IsEmptyElement
  94. XmlNodeType.None, 0, false,
  95. // Name, Prefix, LocalName, NamespaceURI
  96. String.Empty, String.Empty, String.Empty, String.Empty,
  97. // Value, HasValue, AttributeCount, HasAttributes
  98. String.Empty, false, 0, false);
  99. Assert.IsTrue (r.Read (), label + "#2");
  100. XmlAssert.AssertNode (label + "#3", r,
  101. // NodeType, Depth, IsEmptyElement
  102. XmlNodeType.Element, 0, false,
  103. // Name, Prefix, LocalName, NamespaceURI
  104. "root", String.Empty, "root", String.Empty,
  105. // Value, HasValue, AttributeCount, HasAttributes
  106. String.Empty, false, 0, false);
  107. Assert.IsTrue (r.Read (), label + "#4");
  108. XmlAssert.AssertNode (label + "#5", r,
  109. // NodeType, Depth, IsEmptyElement
  110. XmlNodeType.EndElement, 0, false,
  111. // Name, Prefix, LocalName, NamespaceURI
  112. "root", String.Empty, "root", String.Empty,
  113. // Value, HasValue, AttributeCount, HasAttributes
  114. String.Empty, false, 0, false);
  115. Assert.IsFalse (r.Read (), label + "#6");
  116. }
  117. [Test]
  118. public void ReadSubtree3 ()
  119. {
  120. string xml = "<root attr='value'/>";
  121. nav = GetXmlDocumentNavigator (xml);
  122. ReadSubtree3 (nav, "#1.");
  123. nav.MoveToRoot ();
  124. nav.MoveToFirstChild ();
  125. ReadSubtree3 (nav, "#2.");
  126. nav = GetXPathDocumentNavigator (document);
  127. ReadSubtree3 (nav, "#3.");
  128. nav.MoveToRoot ();
  129. nav.MoveToFirstChild ();
  130. ReadSubtree3 (nav, "#4.");
  131. }
  132. void ReadSubtree3 (XPathNavigator nav, string label)
  133. {
  134. XmlReader r = nav.ReadSubtree ();
  135. XmlAssert.AssertNode (label + "#1", r,
  136. // NodeType, Depth, IsEmptyElement
  137. XmlNodeType.None, 0, false,
  138. // Name, Prefix, LocalName, NamespaceURI
  139. String.Empty, String.Empty, String.Empty, String.Empty,
  140. // Value, HasValue, AttributeCount, HasAttributes
  141. String.Empty, false, 0, false);
  142. Assert.IsTrue (r.Read (), label + "#2");
  143. XmlAssert.AssertNode (label + "#3", r,
  144. // NodeType, Depth, IsEmptyElement
  145. XmlNodeType.Element, 0, true,
  146. // Name, Prefix, LocalName, NamespaceURI
  147. "root", String.Empty, "root", String.Empty,
  148. // Value, HasValue, AttributeCount, HasAttributes
  149. String.Empty, false, 1, true);
  150. Assert.IsTrue (r.MoveToFirstAttribute (), label + "#4");
  151. XmlAssert.AssertNode (label + "#5", r,
  152. // NodeType, Depth, IsEmptyElement
  153. XmlNodeType.Attribute, 1, false,
  154. // Name, Prefix, LocalName, NamespaceURI
  155. "attr", String.Empty, "attr", String.Empty,
  156. // Value, HasValue, AttributeCount, HasAttributes
  157. "value", true, 1, true);
  158. Assert.IsTrue (r.ReadAttributeValue (), label + "#6");
  159. XmlAssert.AssertNode (label + "#7", r,
  160. // NodeType, Depth, IsEmptyElement
  161. XmlNodeType.Text, 2, false,
  162. // Name, Prefix, LocalName, NamespaceURI
  163. String.Empty, String.Empty, String.Empty, String.Empty,
  164. // Value, HasValue, AttributeCount, HasAttributes
  165. "value", true, 1, true);
  166. Assert.IsFalse (r.ReadAttributeValue (), label + "#8");
  167. Assert.IsFalse (r.MoveToNextAttribute (), label + "#9");
  168. Assert.IsTrue (r.MoveToElement (), label + "#10");
  169. Assert.IsFalse (r.Read (), label + "#11");
  170. }
  171. [Test]
  172. public void DocElem_OpenClose_Attribute ()
  173. {
  174. string xml = "<root attr='value'></root>";
  175. nav = GetXmlDocumentNavigator (xml);
  176. DocElem_OpenClose_Attribute (nav, "#1.");
  177. nav.MoveToRoot ();
  178. nav.MoveToFirstChild ();
  179. DocElem_OpenClose_Attribute (nav, "#2.");
  180. nav = GetXPathDocumentNavigator (document);
  181. DocElem_OpenClose_Attribute (nav, "#3.");
  182. nav.MoveToRoot ();
  183. nav.MoveToFirstChild ();
  184. DocElem_OpenClose_Attribute (nav, "#4.");
  185. }
  186. void DocElem_OpenClose_Attribute (XPathNavigator nav, string label)
  187. {
  188. XmlReader r = nav.ReadSubtree ();
  189. XmlAssert.AssertNode (label + "#1", r,
  190. // NodeType, Depth, IsEmptyElement
  191. XmlNodeType.None, 0, false,
  192. // Name, Prefix, LocalName, NamespaceURI
  193. String.Empty, String.Empty, String.Empty, String.Empty,
  194. // Value, HasValue, AttributeCount, HasAttributes
  195. String.Empty, false, 0, false);
  196. Assert.IsTrue (r.Read (), label + "#2");
  197. XmlAssert.AssertNode (label + "#3", r,
  198. // NodeType, Depth, IsEmptyElement
  199. XmlNodeType.Element, 0, false,
  200. // Name, Prefix, LocalName, NamespaceURI
  201. "root", String.Empty, "root", String.Empty,
  202. // Value, HasValue, AttributeCount, HasAttributes
  203. String.Empty, false, 1, true);
  204. Assert.IsTrue (r.MoveToFirstAttribute (), label + "#4");
  205. XmlAssert.AssertNode (label + "#5", r,
  206. // NodeType, Depth, IsEmptyElement
  207. XmlNodeType.Attribute, 1, false,
  208. // Name, Prefix, LocalName, NamespaceURI
  209. "attr", String.Empty, "attr", String.Empty,
  210. // Value, HasValue, AttributeCount, HasAttributes
  211. "value", true, 1, true);
  212. Assert.IsTrue (r.ReadAttributeValue (), label + "#6");
  213. XmlAssert.AssertNode (label + "#7", r,
  214. // NodeType, Depth, IsEmptyElement
  215. XmlNodeType.Text, 2, false,
  216. // Name, Prefix, LocalName, NamespaceURI
  217. String.Empty, String.Empty, String.Empty, String.Empty,
  218. // Value, HasValue, AttributeCount, HasAttributes
  219. "value", true, 1, true);
  220. Assert.IsFalse (r.ReadAttributeValue (), label + "#8");
  221. Assert.IsFalse (r.MoveToNextAttribute (), label + "#9");
  222. Assert.IsTrue (r.MoveToElement (), label + "#10");
  223. Assert.IsTrue (r.Read (), label + "#11");
  224. XmlAssert.AssertNode (label + "#12", r,
  225. // NodeType, Depth, IsEmptyElement
  226. XmlNodeType.EndElement, 0, false,
  227. // Name, Prefix, LocalName, NamespaceURI
  228. "root", String.Empty, "root", String.Empty,
  229. // Value, HasValue, AttributeCount, HasAttributes
  230. String.Empty, false, 0, false);
  231. Assert.IsFalse (r.Read (), label + "#13");
  232. }
  233. [Test]
  234. public void FromChildElement ()
  235. {
  236. string xml = "<root><foo attr='value'>test</foo><bar/></root>";
  237. nav = GetXmlDocumentNavigator (xml);
  238. nav.MoveToFirstChild ();
  239. nav.MoveToFirstChild (); // foo
  240. FromChildElement (nav, "#1.");
  241. nav = GetXPathDocumentNavigator (document);
  242. nav.MoveToFirstChild ();
  243. nav.MoveToFirstChild (); // foo
  244. FromChildElement (nav, "#2.");
  245. }
  246. void FromChildElement (XPathNavigator nav, string label)
  247. {
  248. XmlReader r = nav.ReadSubtree ();
  249. XmlAssert.AssertNode (label + "#1", r,
  250. // NodeType, Depth, IsEmptyElement
  251. XmlNodeType.None, 0, false,
  252. // Name, Prefix, LocalName, NamespaceURI
  253. String.Empty, String.Empty, String.Empty, String.Empty,
  254. // Value, HasValue, AttributeCount, HasAttributes
  255. String.Empty, false, 0, false);
  256. Assert.IsTrue (r.Read (), label + "#2");
  257. XmlAssert.AssertNode (label + "#3", r,
  258. // NodeType, Depth, IsEmptyElement
  259. XmlNodeType.Element, 0, false,
  260. // Name, Prefix, LocalName, NamespaceURI
  261. "foo", String.Empty, "foo", String.Empty,
  262. // Value, HasValue, AttributeCount, HasAttributes
  263. String.Empty, false, 1, true);
  264. Assert.IsTrue (r.Read (), label + "#4");
  265. XmlAssert.AssertNode (label + "#5", r,
  266. // NodeType, Depth, IsEmptyElement
  267. XmlNodeType.Text, 1, false,
  268. // Name, Prefix, LocalName, NamespaceURI
  269. String.Empty, String.Empty, String.Empty, String.Empty,
  270. // Value, HasValue, AttributeCount, HasAttributes
  271. "test", true, 0, false);
  272. Assert.IsTrue (r.Read (), label + "#6");
  273. XmlAssert.AssertNode (label + "#7", r,
  274. // NodeType, Depth, IsEmptyElement
  275. XmlNodeType.EndElement, 0, false,
  276. // Name, Prefix, LocalName, NamespaceURI
  277. "foo", String.Empty, "foo", String.Empty,
  278. // Value, HasValue, AttributeCount, HasAttributes
  279. String.Empty, false, 0, false);
  280. // end at </foo>, without moving toward <bar>.
  281. Assert.IsFalse (r.Read (), label + "#8");
  282. }
  283. [Test]
  284. [Category ("NotDotNet")] // MS bug
  285. public void AttributesAndNamespaces ()
  286. {
  287. string xml = "<root attr='value' x:a2='v2' xmlns:x='urn:foo' xmlns='urn:default'></root>";
  288. nav = GetXmlDocumentNavigator (xml);
  289. AttributesAndNamespaces (nav, "#1.");
  290. nav.MoveToRoot ();
  291. nav.MoveToFirstChild ();
  292. AttributesAndNamespaces (nav, "#2.");
  293. nav = GetXPathDocumentNavigator (document);
  294. AttributesAndNamespaces (nav, "#3.");
  295. nav.MoveToRoot ();
  296. nav.MoveToFirstChild ();
  297. AttributesAndNamespaces (nav, "#4.");
  298. }
  299. void AttributesAndNamespaces (XPathNavigator nav, string label)
  300. {
  301. XmlReader r = nav.ReadSubtree ();
  302. XmlAssert.AssertNode (label + "#1", r,
  303. // NodeType, Depth, IsEmptyElement
  304. XmlNodeType.None, 0, false,
  305. // Name, Prefix, LocalName, NamespaceURI
  306. String.Empty, String.Empty, String.Empty, String.Empty,
  307. // Value, HasValue, AttributeCount, HasAttributes
  308. String.Empty, false, 0, false);
  309. Assert.IsTrue (r.Read (), label + "#2");
  310. XmlAssert.AssertNode (label + "#3", r,
  311. // NodeType, Depth, IsEmptyElement
  312. XmlNodeType.Element, 0, false,
  313. // Name, Prefix, LocalName, NamespaceURI
  314. "root", String.Empty, "root", "urn:default",
  315. // Value, HasValue, AttributeCount, HasAttributes
  316. String.Empty, false, 4, true);
  317. // Namespaces
  318. Assert.IsTrue (r.MoveToAttribute ("xmlns:x"), label + "#4");
  319. XmlAssert.AssertNode (label + "#5", r,
  320. // NodeType, Depth, IsEmptyElement
  321. XmlNodeType.Attribute, 1, false,
  322. // Name, Prefix, LocalName, NamespaceURI
  323. "xmlns:x", "xmlns", "x",
  324. "http://www.w3.org/2000/xmlns/",
  325. // Value, HasValue, AttributeCount, HasAttributes
  326. "urn:foo", true, 4, true);
  327. Assert.IsTrue (r.ReadAttributeValue (), label + "#6");
  328. ///* MS.NET has a bug here
  329. XmlAssert.AssertNode (label + "#7", r,
  330. // NodeType, Depth, IsEmptyElement
  331. XmlNodeType.Text, 2, false,
  332. // Name, Prefix, LocalName, NamespaceURI
  333. String.Empty, String.Empty, String.Empty, String.Empty,
  334. // Value, HasValue, AttributeCount, HasAttributes
  335. "urn:foo", true, 4, true);
  336. //*/
  337. Assert.IsFalse (r.ReadAttributeValue (), label + "#8");
  338. Assert.IsTrue (r.MoveToAttribute ("xmlns"), label + "#9");
  339. XmlAssert.AssertNode (label + "#10", r,
  340. // NodeType, Depth, IsEmptyElement
  341. XmlNodeType.Attribute, 1, false,
  342. // Name, Prefix, LocalName, NamespaceURI
  343. "xmlns", String.Empty, "xmlns",
  344. "http://www.w3.org/2000/xmlns/",
  345. // Value, HasValue, AttributeCount, HasAttributes
  346. "urn:default", true, 4, true);
  347. Assert.IsTrue (r.ReadAttributeValue (), label + "#11");
  348. ///* MS.NET has a bug here
  349. XmlAssert.AssertNode (label + "#12", r,
  350. // NodeType, Depth, IsEmptyElement
  351. XmlNodeType.Text, 2, false,
  352. // Name, Prefix, LocalName, NamespaceURI
  353. String.Empty, String.Empty, String.Empty, String.Empty,
  354. // Value, HasValue, AttributeCount, HasAttributes
  355. "urn:default", true, 4, true);
  356. //*/
  357. Assert.IsFalse (r.ReadAttributeValue (), label + "#13");
  358. // Attributes
  359. Assert.IsTrue (r.MoveToAttribute ("attr"), label + "#14");
  360. XmlAssert.AssertNode (label + "#15", r,
  361. // NodeType, Depth, IsEmptyElement
  362. XmlNodeType.Attribute, 1, false,
  363. // Name, Prefix, LocalName, NamespaceURI
  364. "attr", String.Empty, "attr", String.Empty,
  365. // Value, HasValue, AttributeCount, HasAttributes
  366. "value", true, 4, true);
  367. Assert.IsTrue (r.ReadAttributeValue (), label + "#16");
  368. XmlAssert.AssertNode (label + "#17", r,
  369. // NodeType, Depth, IsEmptyElement
  370. XmlNodeType.Text, 2, false,
  371. // Name, Prefix, LocalName, NamespaceURI
  372. String.Empty, String.Empty, String.Empty, String.Empty,
  373. // Value, HasValue, AttributeCount, HasAttributes
  374. "value", true, 4, true);
  375. Assert.IsFalse (r.ReadAttributeValue (), label + "#18");
  376. Assert.IsTrue (r.MoveToAttribute ("x:a2"), label + "#19");
  377. XmlAssert.AssertNode (label + "#20", r,
  378. // NodeType, Depth, IsEmptyElement
  379. XmlNodeType.Attribute, 1, false,
  380. // Name, Prefix, LocalName, NamespaceURI
  381. "x:a2", "x", "a2", "urn:foo",
  382. // Value, HasValue, AttributeCount, HasAttributes
  383. "v2", true, 4, true);
  384. Assert.IsTrue (r.ReadAttributeValue (), label + "#21");
  385. XmlAssert.AssertNode (label + "#22", r,
  386. // NodeType, Depth, IsEmptyElement
  387. XmlNodeType.Text, 2, false,
  388. // Name, Prefix, LocalName, NamespaceURI
  389. String.Empty, String.Empty, String.Empty, String.Empty,
  390. // Value, HasValue, AttributeCount, HasAttributes
  391. "v2", true, 4, true);
  392. Assert.IsTrue (r.MoveToElement (), label + "#24");
  393. Assert.IsTrue (r.Read (), label + "#25");
  394. XmlAssert.AssertNode (label + "#26", r,
  395. // NodeType, Depth, IsEmptyElement
  396. XmlNodeType.EndElement, 0, false,
  397. // Name, Prefix, LocalName, NamespaceURI
  398. "root", String.Empty, "root", "urn:default",
  399. // Value, HasValue, AttributeCount, HasAttributes
  400. String.Empty, false, 0, false);
  401. Assert.IsFalse (r.Read (), label + "#27");
  402. }
  403. [Test]
  404. public void MixedContentAndDepth ()
  405. {
  406. string xml = @"<one> <two>Some data.<three>more</three> done.</two> </one>";
  407. nav = GetXmlDocumentNavigator (xml);
  408. MixedContentAndDepth (nav, "#1.");
  409. nav.MoveToRoot ();
  410. nav.MoveToFirstChild ();
  411. MixedContentAndDepth (nav, "#2.");
  412. nav = GetXPathDocumentNavigator (document);
  413. MixedContentAndDepth (nav, "#3.");
  414. nav.MoveToRoot ();
  415. nav.MoveToFirstChild ();
  416. MixedContentAndDepth (nav, "#4.");
  417. }
  418. void MixedContentAndDepth (XPathNavigator nav, string label)
  419. {
  420. XmlReader r = nav.ReadSubtree ();
  421. r.Read ();
  422. XmlAssert.AssertNode (label + "#1", r,
  423. // NodeType, Depth, IsEmptyElement
  424. XmlNodeType.Element, 0, false,
  425. // Name, Prefix, LocalName, NamespaceURI
  426. "one", String.Empty, "one", String.Empty,
  427. // Value, HasValue, AttributeCount, HasAttributes
  428. String.Empty, false, 0, false);
  429. r.Read ();
  430. XmlAssert.AssertNode (label + "#2", r,
  431. // NodeType, Depth, IsEmptyElement
  432. XmlNodeType.Element, 1, false,
  433. // Name, Prefix, LocalName, NamespaceURI
  434. "two", String.Empty, "two", String.Empty,
  435. // Value, HasValue, AttributeCount, HasAttributes
  436. String.Empty, false, 0, false);
  437. r.Read ();
  438. XmlAssert.AssertNode (label + "#3", r,
  439. // NodeType, Depth, IsEmptyElement
  440. XmlNodeType.Text, 2, false,
  441. // Name, Prefix, LocalName, NamespaceURI
  442. String.Empty, String.Empty, String.Empty, String.Empty,
  443. // Value, HasValue, AttributeCount, HasAttributes
  444. "Some data.", true, 0, false);
  445. r.Read ();
  446. XmlAssert.AssertNode (label + "#4", r,
  447. // NodeType, Depth, IsEmptyElement
  448. XmlNodeType.Element, 2, false,
  449. // Name, Prefix, LocalName, NamespaceURI
  450. "three", String.Empty, "three", String.Empty,
  451. // Value, HasValue, AttributeCount, HasAttributes
  452. String.Empty, false, 0, false);
  453. r.Read ();
  454. XmlAssert.AssertNode (label + "#5", r,
  455. // NodeType, Depth, IsEmptyElement
  456. XmlNodeType.Text, 3, false,
  457. // Name, Prefix, LocalName, NamespaceURI
  458. String.Empty, String.Empty, String.Empty, String.Empty,
  459. // Value, HasValue, AttributeCount, HasAttributes
  460. "more", true, 0, false);
  461. r.Read ();
  462. XmlAssert.AssertNode (label + "#6", r,
  463. // NodeType, Depth, IsEmptyElement
  464. XmlNodeType.EndElement, 2, false,
  465. // Name, Prefix, LocalName, NamespaceURI
  466. "three", String.Empty, "three", String.Empty,
  467. // Value, HasValue, AttributeCount, HasAttributes
  468. String.Empty, false, 0, false);
  469. r.Read ();
  470. XmlAssert.AssertNode (label + "#7", r,
  471. // NodeType, Depth, IsEmptyElement
  472. XmlNodeType.Text, 2, false,
  473. // Name, Prefix, LocalName, NamespaceURI
  474. String.Empty, String.Empty, String.Empty, String.Empty,
  475. // Value, HasValue, AttributeCount, HasAttributes
  476. " done.", true, 0, false);
  477. r.Read ();
  478. XmlAssert.AssertNode (label + "#8", r,
  479. // NodeType, Depth, IsEmptyElement
  480. XmlNodeType.EndElement, 1, false,
  481. // Name, Prefix, LocalName, NamespaceURI
  482. "two", String.Empty, "two", String.Empty,
  483. // Value, HasValue, AttributeCount, HasAttributes
  484. String.Empty, false, 0, false);
  485. r.Read ();
  486. XmlAssert.AssertNode (label + "#9", r,
  487. // NodeType, Depth, IsEmptyElement
  488. XmlNodeType.EndElement, 0, false,
  489. // Name, Prefix, LocalName, NamespaceURI
  490. "one", String.Empty, "one", String.Empty,
  491. // Value, HasValue, AttributeCount, HasAttributes
  492. String.Empty, false, 0, false);
  493. Assert.IsFalse (r.Read (), label + "#10");
  494. }
  495. [Test]
  496. public void MoveToFirstAttributeFromAttribute ()
  497. {
  498. string xml = @"<one xmlns:foo='urn:foo' a='v' />";
  499. nav = GetXmlDocumentNavigator (xml);
  500. MoveToFirstAttributeFromAttribute (nav, "#1.");
  501. nav.MoveToRoot ();
  502. nav.MoveToFirstChild ();
  503. MoveToFirstAttributeFromAttribute (nav, "#2.");
  504. nav = GetXPathDocumentNavigator (document);
  505. MoveToFirstAttributeFromAttribute (nav, "#3.");
  506. nav.MoveToRoot ();
  507. nav.MoveToFirstChild ();
  508. MoveToFirstAttributeFromAttribute (nav, "#4.");
  509. }
  510. void MoveToFirstAttributeFromAttribute (XPathNavigator nav, string label)
  511. {
  512. XmlReader r = nav.ReadSubtree ();
  513. r.MoveToContent ();
  514. Assert.IsTrue (r.MoveToFirstAttribute (), label + "#1");
  515. Assert.IsTrue (r.MoveToFirstAttribute (), label + "#2");
  516. r.ReadAttributeValue ();
  517. Assert.IsTrue (r.MoveToFirstAttribute (), label + "#3");
  518. Assert.IsTrue (r.MoveToNextAttribute (), label + "#4");
  519. Assert.IsTrue (r.MoveToFirstAttribute (), label + "#5");
  520. }
  521. }
  522. }
  523. #endif