XmlTextReaderTests.cs 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849
  1. //
  2. // XmlTextReaderTests.cs
  3. //
  4. // Authors:
  5. // Jason Diamond ([email protected])
  6. // Martin Willemoes Hansen ([email protected])
  7. //
  8. // (C) 2001, 2002 Jason Diamond http://injektilo.org/
  9. //
  10. using System;
  11. using System.IO;
  12. using System.Xml;
  13. using System.Text;
  14. using NUnit.Framework;
  15. namespace MonoTests.System.Xml
  16. {
  17. [TestFixture]
  18. public class XmlTextReaderTests
  19. {
  20. private void AssertStartDocument (XmlReader xmlReader)
  21. {
  22. Assertion.Assert (xmlReader.ReadState == ReadState.Initial);
  23. Assertion.Assert (xmlReader.NodeType == XmlNodeType.None);
  24. Assertion.Assert (xmlReader.Depth == 0);
  25. Assertion.Assert (!xmlReader.EOF);
  26. }
  27. private void AssertNode (
  28. XmlReader xmlReader,
  29. XmlNodeType nodeType,
  30. int depth,
  31. bool isEmptyElement,
  32. string name,
  33. string prefix,
  34. string localName,
  35. string namespaceURI,
  36. string value,
  37. int attributeCount)
  38. {
  39. Assertion.Assert (xmlReader.Read ());
  40. Assertion.Assert (xmlReader.ReadState == ReadState.Interactive);
  41. Assertion.Assert (!xmlReader.EOF);
  42. AssertNodeValues (xmlReader, nodeType, depth, isEmptyElement, name, prefix, localName, namespaceURI, value, attributeCount);
  43. }
  44. private void AssertNodeValues (
  45. XmlReader xmlReader,
  46. XmlNodeType nodeType,
  47. int depth,
  48. bool isEmptyElement,
  49. string name,
  50. string prefix,
  51. string localName,
  52. string namespaceURI,
  53. string value,
  54. int attributeCount)
  55. {
  56. Assertion.AssertEquals ("NodeType", nodeType, xmlReader.NodeType);
  57. Assertion.AssertEquals ("Depth", depth, xmlReader.Depth);
  58. Assertion.AssertEquals ("IsEmptyElement", isEmptyElement, xmlReader.IsEmptyElement);
  59. Assertion.AssertEquals ("name", name, xmlReader.Name);
  60. Assertion.AssertEquals ("prefix", prefix, xmlReader.Prefix);
  61. Assertion.AssertEquals ("localName", localName, xmlReader.LocalName);
  62. Assertion.AssertEquals ("namespaceURI", namespaceURI, xmlReader.NamespaceURI);
  63. Assertion.AssertEquals ("hasValue", (value != String.Empty), xmlReader.HasValue);
  64. Assertion.AssertEquals ("Value", value, xmlReader.Value);
  65. Assertion.AssertEquals ("hasAttributes", attributeCount > 0, xmlReader.HasAttributes);
  66. Assertion.AssertEquals ("attributeCount", attributeCount, xmlReader.AttributeCount);
  67. }
  68. private void AssertAttribute (
  69. XmlReader xmlReader,
  70. string name,
  71. string prefix,
  72. string localName,
  73. string namespaceURI,
  74. string value)
  75. {
  76. Assertion.AssertEquals ("value", value, xmlReader [name]);
  77. Assertion.Assert (xmlReader.GetAttribute (name) == value);
  78. if (namespaceURI != String.Empty) {
  79. Assertion.Assert (xmlReader[localName, namespaceURI] == value);
  80. Assertion.Assert (xmlReader.GetAttribute (localName, namespaceURI) == value);
  81. }
  82. }
  83. private void AssertEndDocument (XmlReader xmlReader)
  84. {
  85. Assertion.Assert ("could read", !xmlReader.Read ());
  86. Assertion.AssertEquals ("NodeType is not XmlNodeType.None", XmlNodeType.None, xmlReader.NodeType);
  87. Assertion.AssertEquals ("Depth is not 0", 0, xmlReader.Depth);
  88. Assertion.AssertEquals ("ReadState is not ReadState.EndOfFile", ReadState.EndOfFile, xmlReader.ReadState);
  89. Assertion.Assert ("not EOF", xmlReader.EOF);
  90. xmlReader.Close ();
  91. Assertion.AssertEquals ("ReadState is not ReadState.Cosed", ReadState.Closed, xmlReader.ReadState);
  92. }
  93. [Test]
  94. public void EmptyElement ()
  95. {
  96. string xml = "<foo/>";
  97. XmlReader xmlReader =
  98. new XmlTextReader (new StringReader (xml));
  99. AssertStartDocument (xmlReader);
  100. AssertNode (
  101. xmlReader, // xmlReader
  102. XmlNodeType.Element, // nodeType
  103. 0, // depth
  104. true, // isEmptyElement
  105. "foo", // name
  106. String.Empty, // prefix
  107. "foo", // localName
  108. String.Empty, // namespaceURI
  109. String.Empty, // value
  110. 0 // attributeCount
  111. );
  112. AssertEndDocument (xmlReader);
  113. }
  114. [Test]
  115. public void EmptyElementWithBadName ()
  116. {
  117. string xml = "<1foo/>";
  118. XmlReader xmlReader =
  119. new XmlTextReader (new StringReader (xml));
  120. bool caughtXmlException = false;
  121. try {
  122. xmlReader.Read();
  123. } catch (XmlException) {
  124. caughtXmlException = true;
  125. }
  126. Assertion.Assert(caughtXmlException);
  127. }
  128. [Test]
  129. public void EmptyElementWithWhitespace ()
  130. {
  131. string xml = "<foo />";
  132. XmlReader xmlReader =
  133. new XmlTextReader (new StringReader (xml));
  134. AssertStartDocument (xmlReader);
  135. AssertNode (
  136. xmlReader, // xmlReader
  137. XmlNodeType.Element, // nodeType
  138. 0, //depth
  139. true, // isEmptyElement
  140. "foo", // name
  141. String.Empty, // prefix
  142. "foo", // localName
  143. String.Empty, // namespaceURI
  144. String.Empty, // value
  145. 0 // attributeCount
  146. );
  147. AssertEndDocument (xmlReader);
  148. }
  149. [Test]
  150. public void EmptyElementWithStartAndEndTag ()
  151. {
  152. string xml = "<foo></foo>";
  153. XmlReader xmlReader =
  154. new XmlTextReader (new StringReader (xml));
  155. AssertStartDocument (xmlReader);
  156. AssertNode (
  157. xmlReader, // xmlReader
  158. XmlNodeType.Element, // nodeType
  159. 0, //depth
  160. false, // isEmptyElement
  161. "foo", // name
  162. String.Empty, // prefix
  163. "foo", // localName
  164. String.Empty, // namespaceURI
  165. String.Empty, // value
  166. 0 // attributeCount
  167. );
  168. AssertNode (
  169. xmlReader, // xmlReader
  170. XmlNodeType.EndElement, // nodeType
  171. 0, //depth
  172. false, // isEmptyElement
  173. "foo", // name
  174. String.Empty, // prefix
  175. "foo", // localName
  176. String.Empty, // namespaceURI
  177. String.Empty, // value
  178. 0 // attributeCount
  179. );
  180. AssertEndDocument (xmlReader);
  181. }
  182. [Test]
  183. public void EmptyElementWithStartAndEndTagWithWhitespace ()
  184. {
  185. string xml = "<foo ></foo >";
  186. XmlReader xmlReader =
  187. new XmlTextReader (new StringReader (xml));
  188. AssertStartDocument (xmlReader);
  189. AssertNode (
  190. xmlReader, // xmlReader
  191. XmlNodeType.Element, // nodeType
  192. 0, //depth
  193. false, // isEmptyElement
  194. "foo", // name
  195. String.Empty, // prefix
  196. "foo", // localName
  197. String.Empty, // namespaceURI
  198. String.Empty, // value
  199. 0 // attributeCount
  200. );
  201. AssertNode (
  202. xmlReader, // xmlReader
  203. XmlNodeType.EndElement, // nodeType
  204. 0, //depth
  205. false, // isEmptyElement
  206. "foo", // name
  207. String.Empty, // prefix
  208. "foo", // localName
  209. String.Empty, // namespaceURI
  210. String.Empty, // value
  211. 0 // attributeCount
  212. );
  213. AssertEndDocument (xmlReader);
  214. }
  215. [Test]
  216. public void NestedEmptyTag ()
  217. {
  218. string xml = "<foo><bar/></foo>";
  219. XmlReader xmlReader =
  220. new XmlTextReader (new StringReader (xml));
  221. AssertStartDocument (xmlReader);
  222. AssertNode (
  223. xmlReader, // xmlReader
  224. XmlNodeType.Element, // nodeType
  225. 0, //depth
  226. false, // isEmptyElement
  227. "foo", // name
  228. String.Empty, // prefix
  229. "foo", // localName
  230. String.Empty, // namespaceURI
  231. String.Empty, // value
  232. 0 // attributeCount
  233. );
  234. AssertNode (
  235. xmlReader, // xmlReader
  236. XmlNodeType.Element, // nodeType
  237. 1, //depth
  238. true, // isEmptyElement
  239. "bar", // name
  240. String.Empty, // prefix
  241. "bar", // localName
  242. String.Empty, // namespaceURI
  243. String.Empty, // value
  244. 0 // attributeCount
  245. );
  246. AssertNode (
  247. xmlReader, // xmlReader
  248. XmlNodeType.EndElement, // nodeType
  249. 0, //depth
  250. false, // isEmptyElement
  251. "foo", // name
  252. String.Empty, // prefix
  253. "foo", // localName
  254. String.Empty, // namespaceURI
  255. String.Empty, // value
  256. 0 // attributeCount
  257. );
  258. AssertEndDocument (xmlReader);
  259. }
  260. [Test]
  261. public void NestedText ()
  262. {
  263. string xml = "<foo>bar</foo>";
  264. XmlReader xmlReader =
  265. new XmlTextReader (new StringReader (xml));
  266. AssertStartDocument (xmlReader);
  267. AssertNode (
  268. xmlReader, // xmlReader
  269. XmlNodeType.Element, // nodeType
  270. 0, //depth
  271. false, // isEmptyElement
  272. "foo", // name
  273. String.Empty, // prefix
  274. "foo", // localName
  275. String.Empty, // namespaceURI
  276. String.Empty, // value
  277. 0 // attributeCount
  278. );
  279. AssertNode (
  280. xmlReader, // xmlReader
  281. XmlNodeType.Text, // nodeType
  282. 1, //depth
  283. false, // isEmptyElement
  284. String.Empty, // name
  285. String.Empty, // prefix
  286. String.Empty, // localName
  287. String.Empty, // namespaceURI
  288. "bar", // value
  289. 0 // attributeCount
  290. );
  291. AssertNode (
  292. xmlReader, // xmlReader
  293. XmlNodeType.EndElement, // nodeType
  294. 0, //depth
  295. false, // isEmptyElement
  296. "foo", // name
  297. String.Empty, // prefix
  298. "foo", // localName
  299. String.Empty, // namespaceURI
  300. String.Empty, // value
  301. 0 // attributeCount
  302. );
  303. AssertEndDocument (xmlReader);
  304. }
  305. [Test]
  306. public void EmptyElementWithAttribute ()
  307. {
  308. string xml = @"<foo bar=""baz""/>";
  309. XmlReader xmlReader =
  310. new XmlTextReader (new StringReader (xml));
  311. AssertStartDocument (xmlReader);
  312. AssertNode (
  313. xmlReader, // xmlReader
  314. XmlNodeType.Element, // nodeType
  315. 0, //depth
  316. true, // isEmptyElement
  317. "foo", // name
  318. String.Empty, // prefix
  319. "foo", // localName
  320. String.Empty, // namespaceURI
  321. String.Empty, // value
  322. 1 // attributeCount
  323. );
  324. AssertAttribute (
  325. xmlReader, // xmlReader
  326. "bar", // name
  327. String.Empty, // prefix
  328. "bar", // localName
  329. String.Empty, // namespaceURI
  330. "baz" // value
  331. );
  332. AssertEndDocument (xmlReader);
  333. }
  334. [Test]
  335. public void StartAndEndTagWithAttribute ()
  336. {
  337. string xml = @"<foo bar='baz'></foo>";
  338. XmlReader xmlReader =
  339. new XmlTextReader (new StringReader (xml));
  340. AssertStartDocument (xmlReader);
  341. AssertNode (
  342. xmlReader, // xmlReader
  343. XmlNodeType.Element, // nodeType
  344. 0, //depth
  345. false, // isEmptyElement
  346. "foo", // name
  347. String.Empty, // prefix
  348. "foo", // localName
  349. String.Empty, // namespaceURI
  350. String.Empty, // value
  351. 1 // attributeCount
  352. );
  353. AssertAttribute (
  354. xmlReader, // xmlReader
  355. "bar", // name
  356. String.Empty, // prefix
  357. "bar", // localName
  358. String.Empty, // namespaceURI
  359. "baz" // value
  360. );
  361. AssertNode (
  362. xmlReader, // xmlReader
  363. XmlNodeType.EndElement, // nodeType
  364. 0, //depth
  365. false, // isEmptyElement
  366. "foo", // name
  367. String.Empty, // prefix
  368. "foo", // localName
  369. String.Empty, // namespaceURI
  370. String.Empty, // value
  371. 0 // attributeCount
  372. );
  373. AssertEndDocument (xmlReader);
  374. }
  375. [Test]
  376. public void EmptyElementWithTwoAttributes ()
  377. {
  378. string xml = @"<foo bar=""baz"" quux='quuux'/>";
  379. XmlReader xmlReader =
  380. new XmlTextReader (new StringReader (xml));
  381. AssertStartDocument (xmlReader);
  382. AssertNode (
  383. xmlReader, // xmlReader
  384. XmlNodeType.Element, // nodeType
  385. 0, //depth
  386. true, // isEmptyElement
  387. "foo", // name
  388. String.Empty, // prefix
  389. "foo", // localName
  390. String.Empty, // namespaceURI
  391. String.Empty, // value
  392. 2 // attributeCount
  393. );
  394. AssertAttribute (
  395. xmlReader, // xmlReader
  396. "bar", // name
  397. String.Empty, // prefix
  398. "bar", // localName
  399. String.Empty, // namespaceURI
  400. "baz" // value
  401. );
  402. AssertAttribute (
  403. xmlReader, // xmlReader
  404. "quux", // name
  405. String.Empty, // prefix
  406. "quux", // localName
  407. String.Empty, // namespaceURI
  408. "quuux" // value
  409. );
  410. AssertEndDocument (xmlReader);
  411. }
  412. [Test]
  413. public void ProcessingInstructionBeforeDocumentElement ()
  414. {
  415. string xml = "<?foo bar?><baz/>";
  416. XmlReader xmlReader =
  417. new XmlTextReader (new StringReader (xml));
  418. AssertStartDocument (xmlReader);
  419. AssertNode (
  420. xmlReader, // xmlReader
  421. XmlNodeType.ProcessingInstruction, // nodeType
  422. 0, //depth
  423. false, // isEmptyElement
  424. "foo", // name
  425. String.Empty, // prefix
  426. "foo", // localName
  427. String.Empty, // namespaceURI
  428. "bar", // value
  429. 0 // attributeCount
  430. );
  431. AssertNode (
  432. xmlReader, // xmlReader
  433. XmlNodeType.Element, // nodeType
  434. 0, //depth
  435. true, // isEmptyElement
  436. "baz", // name
  437. String.Empty, // prefix
  438. "baz", // localName
  439. String.Empty, // namespaceURI
  440. String.Empty, // value
  441. 0 // attributeCount
  442. );
  443. AssertEndDocument (xmlReader);
  444. }
  445. [Test]
  446. public void CommentBeforeDocumentElement ()
  447. {
  448. string xml = "<!--foo--><bar/>";
  449. XmlReader xmlReader =
  450. new XmlTextReader (new StringReader (xml));
  451. AssertStartDocument (xmlReader);
  452. AssertNode (
  453. xmlReader, // xmlReader
  454. XmlNodeType.Comment, // nodeType
  455. 0, //depth
  456. false, // isEmptyElement
  457. String.Empty, // name
  458. String.Empty, // prefix
  459. String.Empty, // localName
  460. String.Empty, // namespaceURI
  461. "foo", // value
  462. 0 // attributeCount
  463. );
  464. AssertNode (
  465. xmlReader, // xmlReader
  466. XmlNodeType.Element, // nodeType
  467. 0, //depth
  468. true, // isEmptyElement
  469. "bar", // name
  470. String.Empty, // prefix
  471. "bar", // localName
  472. String.Empty, // namespaceURI
  473. String.Empty, // value
  474. 0 // attributeCount
  475. );
  476. AssertEndDocument (xmlReader);
  477. }
  478. [Test]
  479. public void PredefinedEntities ()
  480. {
  481. string xml = "<foo>&lt;&gt;&amp;&apos;&quot;</foo>";
  482. XmlReader xmlReader =
  483. new XmlTextReader (new StringReader (xml));
  484. AssertStartDocument (xmlReader);
  485. AssertNode (
  486. xmlReader, // xmlReader
  487. XmlNodeType.Element, // nodeType
  488. 0, //depth
  489. false, // isEmptyElement
  490. "foo", // name
  491. String.Empty, // prefix
  492. "foo", // localName
  493. String.Empty, // namespaceURI
  494. String.Empty, // value
  495. 0 // attributeCount
  496. );
  497. AssertNode (
  498. xmlReader, // xmlReader
  499. XmlNodeType.Text, // nodeType
  500. 1, //depth
  501. false, // isEmptyElement
  502. String.Empty, // name
  503. String.Empty, // prefix
  504. String.Empty, // localName
  505. String.Empty, // namespaceURI
  506. "<>&'\"", // value
  507. 0 // attributeCount
  508. );
  509. AssertNode (
  510. xmlReader, // xmlReader
  511. XmlNodeType.EndElement, // nodeType
  512. 0, //depth
  513. false, // isEmptyElement
  514. "foo", // name
  515. String.Empty, // prefix
  516. "foo", // localName
  517. String.Empty, // namespaceURI
  518. String.Empty, // value
  519. 0 // attributeCount
  520. );
  521. AssertEndDocument (xmlReader);
  522. }
  523. [Test]
  524. public void EntityReference ()
  525. {
  526. string xml = "<foo>&bar;</foo>";
  527. XmlReader xmlReader =
  528. new XmlTextReader (new StringReader (xml));
  529. AssertStartDocument (xmlReader);
  530. AssertNode (
  531. xmlReader, // xmlReader
  532. XmlNodeType.Element, // nodeType
  533. 0, //depth
  534. false, // isEmptyElement
  535. "foo", // name
  536. String.Empty, // prefix
  537. "foo", // localName
  538. String.Empty, // namespaceURI
  539. String.Empty, // value
  540. 0 // attributeCount
  541. );
  542. AssertNode (
  543. xmlReader, // xmlReader
  544. XmlNodeType.EntityReference, // nodeType
  545. 1, //depth
  546. false, // isEmptyElement
  547. "bar", // name
  548. String.Empty, // prefix
  549. "bar", // localName
  550. String.Empty, // namespaceURI
  551. String.Empty, // value
  552. 0 // attributeCount
  553. );
  554. AssertNode (
  555. xmlReader, // xmlReader
  556. XmlNodeType.EndElement, // nodeType
  557. 0, //depth
  558. false, // isEmptyElement
  559. "foo", // name
  560. String.Empty, // prefix
  561. "foo", // localName
  562. String.Empty, // namespaceURI
  563. String.Empty, // value
  564. 0 // attributeCount
  565. );
  566. AssertEndDocument (xmlReader);
  567. }
  568. [Test]
  569. public void EntityReferenceInsideText ()
  570. {
  571. string xml = "<foo>bar&baz;quux</foo>";
  572. XmlReader xmlReader =
  573. new XmlTextReader (new StringReader (xml));
  574. AssertStartDocument (xmlReader);
  575. AssertNode (
  576. xmlReader, // xmlReader
  577. XmlNodeType.Element, // nodeType
  578. 0, //depth
  579. false, // isEmptyElement
  580. "foo", // name
  581. String.Empty, // prefix
  582. "foo", // localName
  583. String.Empty, // namespaceURI
  584. String.Empty, // value
  585. 0 // attributeCount
  586. );
  587. AssertNode (
  588. xmlReader, // xmlReader
  589. XmlNodeType.Text, // nodeType
  590. 1, //depth
  591. false, // isEmptyElement
  592. String.Empty, // name
  593. String.Empty, // prefix
  594. String.Empty, // localName
  595. String.Empty, // namespaceURI
  596. "bar", // value
  597. 0 // attributeCount
  598. );
  599. AssertNode (
  600. xmlReader, // xmlReader
  601. XmlNodeType.EntityReference, // nodeType
  602. 1, //depth
  603. false, // isEmptyElement
  604. "baz", // name
  605. String.Empty, // prefix
  606. "baz", // localName
  607. String.Empty, // namespaceURI
  608. String.Empty, // value
  609. 0 // attributeCount
  610. );
  611. AssertNode (
  612. xmlReader, // xmlReader
  613. XmlNodeType.Text, // nodeType
  614. 1, //depth
  615. false, // isEmptyElement
  616. String.Empty, // name
  617. String.Empty, // prefix
  618. String.Empty, // localName
  619. String.Empty, // namespaceURI
  620. "quux", // value
  621. 0 // attributeCount
  622. );
  623. AssertNode (
  624. xmlReader, // xmlReader
  625. XmlNodeType.EndElement, // nodeType
  626. 0, //depth
  627. false, // isEmptyElement
  628. "foo", // name
  629. String.Empty, // prefix
  630. "foo", // localName
  631. String.Empty, // namespaceURI
  632. String.Empty, // value
  633. 0 // attributeCount
  634. );
  635. AssertEndDocument (xmlReader);
  636. }
  637. [Test]
  638. public void CharacterReferences ()
  639. {
  640. string xml = "<foo>&#70;&#x4F;&#x4f;</foo>";
  641. XmlReader xmlReader =
  642. new XmlTextReader (new StringReader (xml));
  643. AssertStartDocument (xmlReader);
  644. AssertNode (
  645. xmlReader, // xmlReader
  646. XmlNodeType.Element, // nodeType
  647. 0, //depth
  648. false, // isEmptyElement
  649. "foo", // name
  650. String.Empty, // prefix
  651. "foo", // localName
  652. String.Empty, // namespaceURI
  653. String.Empty, // value
  654. 0 // attributeCount
  655. );
  656. AssertNode (
  657. xmlReader, // xmlReader
  658. XmlNodeType.Text, // nodeType
  659. 1, //depth
  660. false, // isEmptyElement
  661. String.Empty, // name
  662. String.Empty, // prefix
  663. String.Empty, // localName
  664. String.Empty, // namespaceURI
  665. "FOO", // value
  666. 0 // attributeCount
  667. );
  668. AssertNode (
  669. xmlReader, // xmlReader
  670. XmlNodeType.EndElement, // nodeType
  671. 0, //depth
  672. false, // isEmptyElement
  673. "foo", // name
  674. String.Empty, // prefix
  675. "foo", // localName
  676. String.Empty, // namespaceURI
  677. String.Empty, // value
  678. 0 // attributeCount
  679. );
  680. AssertEndDocument (xmlReader);
  681. }
  682. [Test]
  683. public void EntityReferenceInAttribute ()
  684. {
  685. string xml = "<foo bar='&baz;'/>";
  686. XmlReader xmlReader =
  687. new XmlTextReader (new StringReader (xml));
  688. AssertStartDocument (xmlReader);
  689. AssertNode (
  690. xmlReader, // xmlReader
  691. XmlNodeType.Element, // nodeType
  692. 0, //depth
  693. true, // isEmptyElement
  694. "foo", // name
  695. String.Empty, // prefix
  696. "foo", // localName
  697. String.Empty, // namespaceURI
  698. String.Empty, // value
  699. 1 // attributeCount
  700. );
  701. AssertAttribute (
  702. xmlReader, // xmlReader
  703. "bar", // name
  704. String.Empty, // prefix
  705. "bar", // localName
  706. String.Empty, // namespaceURI
  707. "&baz;" // value
  708. );
  709. AssertEndDocument (xmlReader);
  710. }
  711. [Test]
  712. public void PredefinedEntitiesInAttribute ()
  713. {
  714. string xml = "<foo bar='&lt;&gt;&amp;&apos;&quot;'/>";
  715. XmlReader xmlReader =
  716. new XmlTextReader (new StringReader (xml));
  717. AssertStartDocument (xmlReader);
  718. AssertNode (
  719. xmlReader, // xmlReader
  720. XmlNodeType.Element, // nodeType
  721. 0, //depth
  722. true, // isEmptyElement
  723. "foo", // name
  724. String.Empty, // prefix
  725. "foo", // localName
  726. String.Empty, // namespaceURI
  727. String.Empty, // value
  728. 1 // attributeCount
  729. );
  730. AssertAttribute (
  731. xmlReader, // xmlReader
  732. "bar", // name
  733. String.Empty, // prefix
  734. "bar", // localName
  735. String.Empty, // namespaceURI
  736. "<>&'\"" // value
  737. );
  738. AssertEndDocument (xmlReader);
  739. }
  740. [Test]
  741. public void CharacterReferencesInAttribute ()
  742. {
  743. string xml = "<foo bar='&#70;&#x4F;&#x4f;'/>";
  744. XmlReader xmlReader =
  745. new XmlTextReader (new StringReader (xml));
  746. AssertStartDocument (xmlReader);
  747. AssertNode (
  748. xmlReader, // xmlReader
  749. XmlNodeType.Element, // nodeType
  750. 0, //depth
  751. true, // isEmptyElement
  752. "foo", // name
  753. String.Empty, // prefix
  754. "foo", // localName
  755. String.Empty, // namespaceURI
  756. String.Empty, // value
  757. 1 // attributeCount
  758. );
  759. AssertAttribute (
  760. xmlReader, // xmlReader
  761. "bar", // name
  762. String.Empty, // prefix
  763. "bar", // localName
  764. String.Empty, // namespaceURI
  765. "FOO" // value
  766. );
  767. AssertEndDocument (xmlReader);
  768. }
  769. [Test]
  770. public void CDATA ()
  771. {
  772. string xml = "<foo><![CDATA[<>&]]></foo>";
  773. XmlReader xmlReader =
  774. new XmlTextReader (new StringReader (xml));
  775. AssertStartDocument (xmlReader);
  776. AssertNode (
  777. xmlReader, // xmlReader
  778. XmlNodeType.Element, // nodeType
  779. 0, //depth
  780. false, // isEmptyElement
  781. "foo", // name
  782. String.Empty, // prefix
  783. "foo", // localName
  784. String.Empty, // namespaceURI
  785. String.Empty, // value
  786. 0 // attributeCount
  787. );
  788. AssertNode (
  789. xmlReader, // xmlReader
  790. XmlNodeType.CDATA, // nodeType
  791. 1, //depth
  792. false, // isEmptyElement
  793. String.Empty, // name
  794. String.Empty, // prefix
  795. String.Empty, // localName
  796. String.Empty, // namespaceURI
  797. "<>&", // value
  798. 0 // attributeCount
  799. );
  800. AssertNode (
  801. xmlReader, // xmlReader
  802. XmlNodeType.EndElement, // nodeType
  803. 0, //depth
  804. false, // isEmptyElement
  805. "foo", // name
  806. String.Empty, // prefix
  807. "foo", // localName
  808. String.Empty, // namespaceURI
  809. String.Empty, // value
  810. 0 // attributeCount
  811. );
  812. AssertEndDocument (xmlReader);
  813. }
  814. [Test]
  815. public void EmptyElementInNamespace ()
  816. {
  817. string xml = @"<foo:bar xmlns:foo='http://foo/' />";
  818. XmlReader xmlReader =
  819. new XmlTextReader (new StringReader (xml));
  820. AssertStartDocument (xmlReader);
  821. AssertNode (
  822. xmlReader, // xmlReader
  823. XmlNodeType.Element, // nodeType
  824. 0, // depth
  825. true, // isEmptyElement
  826. "foo:bar", // name
  827. "foo", // prefix
  828. "bar", // localName
  829. "http://foo/", // namespaceURI
  830. String.Empty, // value
  831. 1 // attributeCount
  832. );
  833. AssertAttribute (
  834. xmlReader, // xmlReader
  835. "xmlns:foo", // name
  836. "xmlns", // prefix
  837. "foo", // localName
  838. "http://www.w3.org/2000/xmlns/", // namespaceURI
  839. "http://foo/" // value
  840. );
  841. Assertion.AssertEquals ("http://foo/", xmlReader.LookupNamespace ("foo"));
  842. AssertEndDocument (xmlReader);
  843. }
  844. [Test]
  845. public void EmptyElementInDefaultNamespace ()
  846. {
  847. string xml = @"<foo xmlns='http://foo/' />";
  848. XmlReader xmlReader =
  849. new XmlTextReader (new StringReader (xml));
  850. AssertStartDocument (xmlReader);
  851. AssertNode (
  852. xmlReader, // xmlReader
  853. XmlNodeType.Element, // nodeType
  854. 0, // depth
  855. true, // isEmptyElement
  856. "foo", // name
  857. String.Empty, // prefix
  858. "foo", // localName
  859. "http://foo/", // namespaceURI
  860. String.Empty, // value
  861. 1 // attributeCount
  862. );
  863. AssertAttribute (
  864. xmlReader, // xmlReader
  865. "xmlns", // name
  866. String.Empty, // prefix
  867. "xmlns", // localName
  868. "http://www.w3.org/2000/xmlns/", // namespaceURI
  869. "http://foo/" // value
  870. );
  871. Assertion.AssertEquals ("http://foo/", xmlReader.LookupNamespace (String.Empty));
  872. AssertEndDocument (xmlReader);
  873. }
  874. [Test]
  875. public void ChildElementInNamespace ()
  876. {
  877. string xml = @"<foo:bar xmlns:foo='http://foo/'><baz:quux xmlns:baz='http://baz/' /></foo:bar>";
  878. XmlReader xmlReader =
  879. new XmlTextReader (new StringReader (xml));
  880. AssertStartDocument (xmlReader);
  881. AssertNode (
  882. xmlReader, // xmlReader
  883. XmlNodeType.Element, // nodeType
  884. 0, // depth
  885. false, // isEmptyElement
  886. "foo:bar", // name
  887. "foo", // prefix
  888. "bar", // localName
  889. "http://foo/", // namespaceURI
  890. String.Empty, // value
  891. 1 // attributeCount
  892. );
  893. AssertAttribute (
  894. xmlReader, // xmlReader
  895. "xmlns:foo", // name
  896. "xmlns", // prefix
  897. "foo", // localName
  898. "http://www.w3.org/2000/xmlns/", // namespaceURI
  899. "http://foo/" // value
  900. );
  901. Assertion.AssertEquals ("http://foo/", xmlReader.LookupNamespace ("foo"));
  902. AssertNode (
  903. xmlReader, // xmlReader
  904. XmlNodeType.Element, // nodeType
  905. 1, // depth
  906. true, // isEmptyElement
  907. "baz:quux", // name
  908. "baz", // prefix
  909. "quux", // localName
  910. "http://baz/", // namespaceURI
  911. String.Empty, // value
  912. 1 // attributeCount
  913. );
  914. AssertAttribute (
  915. xmlReader, // xmlReader
  916. "xmlns:baz", // name
  917. "xmlns", // prefix
  918. "baz", // localName
  919. "http://www.w3.org/2000/xmlns/", // namespaceURI
  920. "http://baz/" // value
  921. );
  922. Assertion.AssertEquals ("http://foo/", xmlReader.LookupNamespace ("foo"));
  923. Assertion.AssertEquals ("http://baz/", xmlReader.LookupNamespace ("baz"));
  924. AssertNode (
  925. xmlReader, // xmlReader
  926. XmlNodeType.EndElement, // nodeType
  927. 0, // depth
  928. false, // isEmptyElement
  929. "foo:bar", // name
  930. "foo", // prefix
  931. "bar", // localName
  932. "http://foo/", // namespaceURI
  933. String.Empty, // value
  934. 0 // attributeCount
  935. );
  936. Assertion.AssertEquals ("http://foo/", xmlReader.LookupNamespace ("foo"));
  937. Assertion.AssertNull (xmlReader.LookupNamespace ("baz"));
  938. AssertEndDocument (xmlReader);
  939. }
  940. [Test]
  941. public void ChildElementInDefaultNamespace ()
  942. {
  943. string xml = @"<foo:bar xmlns:foo='http://foo/'><baz xmlns='http://baz/' /></foo:bar>";
  944. XmlReader xmlReader =
  945. new XmlTextReader (new StringReader (xml));
  946. AssertStartDocument (xmlReader);
  947. AssertNode (
  948. xmlReader, // xmlReader
  949. XmlNodeType.Element, // nodeType
  950. 0, // depth
  951. false, // isEmptyElement
  952. "foo:bar", // name
  953. "foo", // prefix
  954. "bar", // localName
  955. "http://foo/", // namespaceURI
  956. String.Empty, // value
  957. 1 // attributeCount
  958. );
  959. AssertAttribute (
  960. xmlReader, // xmlReader
  961. "xmlns:foo", // name
  962. "xmlns", // prefix
  963. "foo", // localName
  964. "http://www.w3.org/2000/xmlns/", // namespaceURI
  965. "http://foo/" // value
  966. );
  967. Assertion.AssertEquals ("http://foo/", xmlReader.LookupNamespace ("foo"));
  968. AssertNode (
  969. xmlReader, // xmlReader
  970. XmlNodeType.Element, // nodeType
  971. 1, // depth
  972. true, // isEmptyElement
  973. "baz", // name
  974. String.Empty, // prefix
  975. "baz", // localName
  976. "http://baz/", // namespaceURI
  977. String.Empty, // value
  978. 1 // attributeCount
  979. );
  980. AssertAttribute (
  981. xmlReader, // xmlReader
  982. "xmlns", // name
  983. String.Empty, // prefix
  984. "xmlns", // localName
  985. "http://www.w3.org/2000/xmlns/", // namespaceURI
  986. "http://baz/" // value
  987. );
  988. Assertion.AssertEquals ("http://foo/", xmlReader.LookupNamespace ("foo"));
  989. Assertion.AssertEquals ("http://baz/", xmlReader.LookupNamespace (String.Empty));
  990. AssertNode (
  991. xmlReader, // xmlReader
  992. XmlNodeType.EndElement, // nodeType
  993. 0, // depth
  994. false, // isEmptyElement
  995. "foo:bar", // name
  996. "foo", // prefix
  997. "bar", // localName
  998. "http://foo/", // namespaceURI
  999. String.Empty, // value
  1000. 0 // attributeCount
  1001. );
  1002. Assertion.AssertEquals ("http://foo/", xmlReader.LookupNamespace ("foo"));
  1003. AssertEndDocument (xmlReader);
  1004. }
  1005. [Test]
  1006. public void AttributeInNamespace ()
  1007. {
  1008. string xml = @"<foo bar:baz='quux' xmlns:bar='http://bar/' />";
  1009. XmlReader xmlReader =
  1010. new XmlTextReader (new StringReader (xml));
  1011. AssertStartDocument (xmlReader);
  1012. AssertNode (
  1013. xmlReader, // xmlReader
  1014. XmlNodeType.Element, // nodeType
  1015. 0, // depth
  1016. true, // isEmptyElement
  1017. "foo", // name
  1018. String.Empty, // prefix
  1019. "foo", // localName
  1020. String.Empty, // namespaceURI
  1021. String.Empty, // value
  1022. 2 // attributeCount
  1023. );
  1024. AssertAttribute (
  1025. xmlReader, // xmlReader
  1026. "bar:baz", // name
  1027. "bar", // prefix
  1028. "baz", // localName
  1029. "http://bar/", // namespaceURI
  1030. "quux" // value
  1031. );
  1032. AssertAttribute (
  1033. xmlReader, // xmlReader
  1034. "xmlns:bar", // name
  1035. "xmlns", // prefix
  1036. "bar", // localName
  1037. "http://www.w3.org/2000/xmlns/", // namespaceURI
  1038. "http://bar/" // value
  1039. );
  1040. Assertion.AssertEquals ("http://bar/", xmlReader.LookupNamespace ("bar"));
  1041. AssertEndDocument (xmlReader);
  1042. }
  1043. // The following is #if'ed out because it's specific to the Mono
  1044. // implementation and won't compile when testing Microsoft's code.
  1045. // Feel free to turn it on if you want to test Mono's name tables.
  1046. #if false
  1047. [Test]
  1048. public void IsFirstNameCharTest ()
  1049. {
  1050. for (int ch = 0; ch <= 0xFFFF; ++ch) {
  1051. Assertion.Assert (
  1052. XmlChar.IsFirstNameChar (ch) ==
  1053. IsFirstNameChar (ch));
  1054. }
  1055. }
  1056. [Test]
  1057. public void IsNameCharTest ()
  1058. {
  1059. for (int ch = 0; ch <= 0xFFFF; ++ch) {
  1060. Assertion.Assert (
  1061. XmlChar.IsNameChar (ch) ==
  1062. IsNameChar (ch));
  1063. }
  1064. }
  1065. private static bool IsFirstNameChar (int ch)
  1066. {
  1067. return
  1068. IsLetter (ch) ||
  1069. (ch == '_') ||
  1070. (ch == ':');
  1071. }
  1072. private static bool IsNameChar (int ch)
  1073. {
  1074. return
  1075. IsLetter (ch) ||
  1076. IsDigit (ch) ||
  1077. (ch == '.') ||
  1078. (ch == '-') ||
  1079. (ch == '_') ||
  1080. (ch == ':') ||
  1081. IsCombiningChar (ch) ||
  1082. IsExtender (ch);
  1083. }
  1084. private static bool IsLetter (int ch)
  1085. {
  1086. return
  1087. IsBaseChar (ch) ||
  1088. IsIdeographic (ch);
  1089. }
  1090. private static bool IsBaseChar (int ch)
  1091. {
  1092. return
  1093. (ch >= 0x0041 && ch <= 0x005A) ||
  1094. (ch >= 0x0061 && ch <= 0x007A) ||
  1095. (ch >= 0x00C0 && ch <= 0x00D6) ||
  1096. (ch >= 0x00D8 && ch <= 0x00F6) ||
  1097. (ch >= 0x00F8 && ch <= 0x00FF) ||
  1098. (ch >= 0x0100 && ch <= 0x0131) ||
  1099. (ch >= 0x0134 && ch <= 0x013E) ||
  1100. (ch >= 0x0141 && ch <= 0x0148) ||
  1101. (ch >= 0x014A && ch <= 0x017E) ||
  1102. (ch >= 0x0180 && ch <= 0x01C3) ||
  1103. (ch >= 0x01CD && ch <= 0x01F0) ||
  1104. (ch >= 0x01F4 && ch <= 0x01F5) ||
  1105. (ch >= 0x01FA && ch <= 0x0217) ||
  1106. (ch >= 0x0250 && ch <= 0x02A8) ||
  1107. (ch >= 0x02BB && ch <= 0x02C1) ||
  1108. (ch == 0x0386) ||
  1109. (ch >= 0x0388 && ch <= 0x038A) ||
  1110. (ch == 0x038C) ||
  1111. (ch >= 0x038E && ch <= 0x03A1) ||
  1112. (ch >= 0x03A3 && ch <= 0x03CE) ||
  1113. (ch >= 0x03D0 && ch <= 0x03D6) ||
  1114. (ch == 0x03DA) ||
  1115. (ch == 0x03DC) ||
  1116. (ch == 0x03DE) ||
  1117. (ch == 0x03E0) ||
  1118. (ch >= 0x03E2 && ch <= 0x03F3) ||
  1119. (ch >= 0x0401 && ch <= 0x040C) ||
  1120. (ch >= 0x040E && ch <= 0x044F) ||
  1121. (ch >= 0x0451 && ch <= 0x045C) ||
  1122. (ch >= 0x045E && ch <= 0x0481) ||
  1123. (ch >= 0x0490 && ch <= 0x04C4) ||
  1124. (ch >= 0x04C7 && ch <= 0x04C8) ||
  1125. (ch >= 0x04CB && ch <= 0x04CC) ||
  1126. (ch >= 0x04D0 && ch <= 0x04EB) ||
  1127. (ch >= 0x04EE && ch <= 0x04F5) ||
  1128. (ch >= 0x04F8 && ch <= 0x04F9) ||
  1129. (ch >= 0x0531 && ch <= 0x0556) ||
  1130. (ch == 0x0559) ||
  1131. (ch >= 0x0561 && ch <= 0x0586) ||
  1132. (ch >= 0x05D0 && ch <= 0x05EA) ||
  1133. (ch >= 0x05F0 && ch <= 0x05F2) ||
  1134. (ch >= 0x0621 && ch <= 0x063A) ||
  1135. (ch >= 0x0641 && ch <= 0x064A) ||
  1136. (ch >= 0x0671 && ch <= 0x06B7) ||
  1137. (ch >= 0x06BA && ch <= 0x06BE) ||
  1138. (ch >= 0x06C0 && ch <= 0x06CE) ||
  1139. (ch >= 0x06D0 && ch <= 0x06D3) ||
  1140. (ch == 0x06D5) ||
  1141. (ch >= 0x06E5 && ch <= 0x06E6) ||
  1142. (ch >= 0x0905 && ch <= 0x0939) ||
  1143. (ch == 0x093D) ||
  1144. (ch >= 0x0958 && ch <= 0x0961) ||
  1145. (ch >= 0x0985 && ch <= 0x098C) ||
  1146. (ch >= 0x098F && ch <= 0x0990) ||
  1147. (ch >= 0x0993 && ch <= 0x09A8) ||
  1148. (ch >= 0x09AA && ch <= 0x09B0) ||
  1149. (ch == 0x09B2) ||
  1150. (ch >= 0x09B6 && ch <= 0x09B9) ||
  1151. (ch >= 0x09DC && ch <= 0x09DD) ||
  1152. (ch >= 0x09DF && ch <= 0x09E1) ||
  1153. (ch >= 0x09F0 && ch <= 0x09F1) ||
  1154. (ch >= 0x0A05 && ch <= 0x0A0A) ||
  1155. (ch >= 0x0A0F && ch <= 0x0A10) ||
  1156. (ch >= 0x0A13 && ch <= 0x0A28) ||
  1157. (ch >= 0x0A2A && ch <= 0x0A30) ||
  1158. (ch >= 0x0A32 && ch <= 0x0A33) ||
  1159. (ch >= 0x0A35 && ch <= 0x0A36) ||
  1160. (ch >= 0x0A38 && ch <= 0x0A39) ||
  1161. (ch >= 0x0A59 && ch <= 0x0A5C) ||
  1162. (ch == 0x0A5E) ||
  1163. (ch >= 0x0A72 && ch <= 0x0A74) ||
  1164. (ch >= 0x0A85 && ch <= 0x0A8B) ||
  1165. (ch == 0x0A8D) ||
  1166. (ch >= 0x0A8F && ch <= 0x0A91) ||
  1167. (ch >= 0x0A93 && ch <= 0x0AA8) ||
  1168. (ch >= 0x0AAA && ch <= 0x0AB0) ||
  1169. (ch >= 0x0AB2 && ch <= 0x0AB3) ||
  1170. (ch >= 0x0AB5 && ch <= 0x0AB9) ||
  1171. (ch == 0x0ABD) ||
  1172. (ch == 0x0AE0) ||
  1173. (ch >= 0x0B05 && ch <= 0x0B0C) ||
  1174. (ch >= 0x0B0F && ch <= 0x0B10) ||
  1175. (ch >= 0x0B13 && ch <= 0x0B28) ||
  1176. (ch >= 0x0B2A && ch <= 0x0B30) ||
  1177. (ch >= 0x0B32 && ch <= 0x0B33) ||
  1178. (ch >= 0x0B36 && ch <= 0x0B39) ||
  1179. (ch == 0x0B3D) ||
  1180. (ch >= 0x0B5C && ch <= 0x0B5D) ||
  1181. (ch >= 0x0B5F && ch <= 0x0B61) ||
  1182. (ch >= 0x0B85 && ch <= 0x0B8A) ||
  1183. (ch >= 0x0B8E && ch <= 0x0B90) ||
  1184. (ch >= 0x0B92 && ch <= 0x0B95) ||
  1185. (ch >= 0x0B99 && ch <= 0x0B9A) ||
  1186. (ch == 0x0B9C) ||
  1187. (ch >= 0x0B9E && ch <= 0x0B9F) ||
  1188. (ch >= 0x0BA3 && ch <= 0x0BA4) ||
  1189. (ch >= 0x0BA8 && ch <= 0x0BAA) ||
  1190. (ch >= 0x0BAE && ch <= 0x0BB5) ||
  1191. (ch >= 0x0BB7 && ch <= 0x0BB9) ||
  1192. (ch >= 0x0C05 && ch <= 0x0C0C) ||
  1193. (ch >= 0x0C0E && ch <= 0x0C10) ||
  1194. (ch >= 0x0C12 && ch <= 0x0C28) ||
  1195. (ch >= 0x0C2A && ch <= 0x0C33) ||
  1196. (ch >= 0x0C35 && ch <= 0x0C39) ||
  1197. (ch >= 0x0C60 && ch <= 0x0C61) ||
  1198. (ch >= 0x0C85 && ch <= 0x0C8C) ||
  1199. (ch >= 0x0C8E && ch <= 0x0C90) ||
  1200. (ch >= 0x0C92 && ch <= 0x0CA8) ||
  1201. (ch >= 0x0CAA && ch <= 0x0CB3) ||
  1202. (ch >= 0x0CB5 && ch <= 0x0CB9) ||
  1203. (ch == 0x0CDE) ||
  1204. (ch >= 0x0CE0 && ch <= 0x0CE1) ||
  1205. (ch >= 0x0D05 && ch <= 0x0D0C) ||
  1206. (ch >= 0x0D0E && ch <= 0x0D10) ||
  1207. (ch >= 0x0D12 && ch <= 0x0D28) ||
  1208. (ch >= 0x0D2A && ch <= 0x0D39) ||
  1209. (ch >= 0x0D60 && ch <= 0x0D61) ||
  1210. (ch >= 0x0E01 && ch <= 0x0E2E) ||
  1211. (ch == 0x0E30) ||
  1212. (ch >= 0x0E32 && ch <= 0x0E33) ||
  1213. (ch >= 0x0E40 && ch <= 0x0E45) ||
  1214. (ch >= 0x0E81 && ch <= 0x0E82) ||
  1215. (ch == 0x0E84) ||
  1216. (ch >= 0x0E87 && ch <= 0x0E88) ||
  1217. (ch == 0x0E8A) ||
  1218. (ch == 0x0E8D) ||
  1219. (ch >= 0x0E94 && ch <= 0x0E97) ||
  1220. (ch >= 0x0E99 && ch <= 0x0E9F) ||
  1221. (ch >= 0x0EA1 && ch <= 0x0EA3) ||
  1222. (ch == 0x0EA5) ||
  1223. (ch == 0x0EA7) ||
  1224. (ch >= 0x0EAA && ch <= 0x0EAB) ||
  1225. (ch >= 0x0EAD && ch <= 0x0EAE) ||
  1226. (ch == 0x0EB0) ||
  1227. (ch >= 0x0EB2 && ch <= 0x0EB3) ||
  1228. (ch == 0x0EBD) ||
  1229. (ch >= 0x0EC0 && ch <= 0x0EC4) ||
  1230. (ch >= 0x0F40 && ch <= 0x0F47) ||
  1231. (ch >= 0x0F49 && ch <= 0x0F69) ||
  1232. (ch >= 0x10A0 && ch <= 0x10C5) ||
  1233. (ch >= 0x10D0 && ch <= 0x10F6) ||
  1234. (ch == 0x1100) ||
  1235. (ch >= 0x1102 && ch <= 0x1103) ||
  1236. (ch >= 0x1105 && ch <= 0x1107) ||
  1237. (ch == 0x1109) ||
  1238. (ch >= 0x110B && ch <= 0x110C) ||
  1239. (ch >= 0x110E && ch <= 0x1112) ||
  1240. (ch == 0x113C) ||
  1241. (ch == 0x113E) ||
  1242. (ch == 0x1140) ||
  1243. (ch == 0x114C) ||
  1244. (ch == 0x114E) ||
  1245. (ch == 0x1150) ||
  1246. (ch >= 0x1154 && ch <= 0x1155) ||
  1247. (ch == 0x1159) ||
  1248. (ch >= 0x115F && ch <= 0x1161) ||
  1249. (ch == 0x1163) ||
  1250. (ch == 0x1165) ||
  1251. (ch == 0x1167) ||
  1252. (ch == 0x1169) ||
  1253. (ch >= 0x116D && ch <= 0x116E) ||
  1254. (ch >= 0x1172 && ch <= 0x1173) ||
  1255. (ch == 0x1175) ||
  1256. (ch == 0x119E) ||
  1257. (ch == 0x11A8) ||
  1258. (ch == 0x11AB) ||
  1259. (ch >= 0x11AE && ch <= 0x11AF) ||
  1260. (ch >= 0x11B7 && ch <= 0x11B8) ||
  1261. (ch == 0x11BA) ||
  1262. (ch >= 0x11BC && ch <= 0x11C2) ||
  1263. (ch == 0x11EB) ||
  1264. (ch == 0x11F0) ||
  1265. (ch == 0x11F9) ||
  1266. (ch >= 0x1E00 && ch <= 0x1E9B) ||
  1267. (ch >= 0x1EA0 && ch <= 0x1EF9) ||
  1268. (ch >= 0x1F00 && ch <= 0x1F15) ||
  1269. (ch >= 0x1F18 && ch <= 0x1F1D) ||
  1270. (ch >= 0x1F20 && ch <= 0x1F45) ||
  1271. (ch >= 0x1F48 && ch <= 0x1F4D) ||
  1272. (ch >= 0x1F50 && ch <= 0x1F57) ||
  1273. (ch == 0x1F59) ||
  1274. (ch == 0x1F5B) ||
  1275. (ch == 0x1F5D) ||
  1276. (ch >= 0x1F5F && ch <= 0x1F7D) ||
  1277. (ch >= 0x1F80 && ch <= 0x1FB4) ||
  1278. (ch >= 0x1FB6 && ch <= 0x1FBC) ||
  1279. (ch == 0x1FBE) ||
  1280. (ch >= 0x1FC2 && ch <= 0x1FC4) ||
  1281. (ch >= 0x1FC6 && ch <= 0x1FCC) ||
  1282. (ch >= 0x1FD0 && ch <= 0x1FD3) ||
  1283. (ch >= 0x1FD6 && ch <= 0x1FDB) ||
  1284. (ch >= 0x1FE0 && ch <= 0x1FEC) ||
  1285. (ch >= 0x1FF2 && ch <= 0x1FF4) ||
  1286. (ch >= 0x1FF6 && ch <= 0x1FFC) ||
  1287. (ch == 0x2126) ||
  1288. (ch >= 0x212A && ch <= 0x212B) ||
  1289. (ch == 0x212E) ||
  1290. (ch >= 0x2180 && ch <= 0x2182) ||
  1291. (ch >= 0x3041 && ch <= 0x3094) ||
  1292. (ch >= 0x30A1 && ch <= 0x30FA) ||
  1293. (ch >= 0x3105 && ch <= 0x312C) ||
  1294. (ch >= 0xAC00 && ch <= 0xD7A3);
  1295. }
  1296. private static bool IsIdeographic (int ch)
  1297. {
  1298. return
  1299. (ch >= 0x4E00 && ch <= 0x9FA5) ||
  1300. (ch == 0x3007) ||
  1301. (ch >= 0x3021 && ch <= 0x3029);
  1302. }
  1303. private static bool IsDigit (int ch)
  1304. {
  1305. return
  1306. (ch >= 0x0030 && ch <= 0x0039) ||
  1307. (ch >= 0x0660 && ch <= 0x0669) ||
  1308. (ch >= 0x06F0 && ch <= 0x06F9) ||
  1309. (ch >= 0x0966 && ch <= 0x096F) ||
  1310. (ch >= 0x09E6 && ch <= 0x09EF) ||
  1311. (ch >= 0x0A66 && ch <= 0x0A6F) ||
  1312. (ch >= 0x0AE6 && ch <= 0x0AEF) ||
  1313. (ch >= 0x0B66 && ch <= 0x0B6F) ||
  1314. (ch >= 0x0BE7 && ch <= 0x0BEF) ||
  1315. (ch >= 0x0C66 && ch <= 0x0C6F) ||
  1316. (ch >= 0x0CE6 && ch <= 0x0CEF) ||
  1317. (ch >= 0x0D66 && ch <= 0x0D6F) ||
  1318. (ch >= 0x0E50 && ch <= 0x0E59) ||
  1319. (ch >= 0x0ED0 && ch <= 0x0ED9) ||
  1320. (ch >= 0x0F20 && ch <= 0x0F29);
  1321. }
  1322. private static bool IsCombiningChar (int ch)
  1323. {
  1324. return
  1325. (ch >= 0x0300 && ch <= 0x0345) ||
  1326. (ch >= 0x0360 && ch <= 0x0361) ||
  1327. (ch >= 0x0483 && ch <= 0x0486) ||
  1328. (ch >= 0x0591 && ch <= 0x05A1) ||
  1329. (ch >= 0x05A3 && ch <= 0x05B9) ||
  1330. (ch >= 0x05BB && ch <= 0x05BD) ||
  1331. (ch == 0x05BF) ||
  1332. (ch >= 0x05C1 && ch <= 0x05C2) ||
  1333. (ch == 0x05C4) ||
  1334. (ch >= 0x064B && ch <= 0x0652) ||
  1335. (ch == 0x0670) ||
  1336. (ch >= 0x06D6 && ch <= 0x06DC) ||
  1337. (ch >= 0x06DD && ch <= 0x06DF) ||
  1338. (ch >= 0x06E0 && ch <= 0x06E4) ||
  1339. (ch >= 0x06E7 && ch <= 0x06E8) ||
  1340. (ch >= 0x06EA && ch <= 0x06ED) ||
  1341. (ch >= 0x0901 && ch <= 0x0903) ||
  1342. (ch == 0x093C) ||
  1343. (ch >= 0x093E && ch <= 0x094C) ||
  1344. (ch == 0x094D) ||
  1345. (ch >= 0x0951 && ch <= 0x0954) ||
  1346. (ch >= 0x0962 && ch <= 0x0963) ||
  1347. (ch >= 0x0981 && ch <= 0x0983) ||
  1348. (ch == 0x09BC) ||
  1349. (ch == 0x09BE) ||
  1350. (ch == 0x09BF) ||
  1351. (ch >= 0x09C0 && ch <= 0x09C4) ||
  1352. (ch >= 0x09C7 && ch <= 0x09C8) ||
  1353. (ch >= 0x09CB && ch <= 0x09CD) ||
  1354. (ch == 0x09D7) ||
  1355. (ch >= 0x09E2 && ch <= 0x09E3) ||
  1356. (ch == 0x0A02) ||
  1357. (ch == 0x0A3C) ||
  1358. (ch == 0x0A3E) ||
  1359. (ch == 0x0A3F) ||
  1360. (ch >= 0x0A40 && ch <= 0x0A42) ||
  1361. (ch >= 0x0A47 && ch <= 0x0A48) ||
  1362. (ch >= 0x0A4B && ch <= 0x0A4D) ||
  1363. (ch >= 0x0A70 && ch <= 0x0A71) ||
  1364. (ch >= 0x0A81 && ch <= 0x0A83) ||
  1365. (ch == 0x0ABC) ||
  1366. (ch >= 0x0ABE && ch <= 0x0AC5) ||
  1367. (ch >= 0x0AC7 && ch <= 0x0AC9) ||
  1368. (ch >= 0x0ACB && ch <= 0x0ACD) ||
  1369. (ch >= 0x0B01 && ch <= 0x0B03) ||
  1370. (ch == 0x0B3C) ||
  1371. (ch >= 0x0B3E && ch <= 0x0B43) ||
  1372. (ch >= 0x0B47 && ch <= 0x0B48) ||
  1373. (ch >= 0x0B4B && ch <= 0x0B4D) ||
  1374. (ch >= 0x0B56 && ch <= 0x0B57) ||
  1375. (ch >= 0x0B82 && ch <= 0x0B83) ||
  1376. (ch >= 0x0BBE && ch <= 0x0BC2) ||
  1377. (ch >= 0x0BC6 && ch <= 0x0BC8) ||
  1378. (ch >= 0x0BCA && ch <= 0x0BCD) ||
  1379. (ch == 0x0BD7) ||
  1380. (ch >= 0x0C01 && ch <= 0x0C03) ||
  1381. (ch >= 0x0C3E && ch <= 0x0C44) ||
  1382. (ch >= 0x0C46 && ch <= 0x0C48) ||
  1383. (ch >= 0x0C4A && ch <= 0x0C4D) ||
  1384. (ch >= 0x0C55 && ch <= 0x0C56) ||
  1385. (ch >= 0x0C82 && ch <= 0x0C83) ||
  1386. (ch >= 0x0CBE && ch <= 0x0CC4) ||
  1387. (ch >= 0x0CC6 && ch <= 0x0CC8) ||
  1388. (ch >= 0x0CCA && ch <= 0x0CCD) ||
  1389. (ch >= 0x0CD5 && ch <= 0x0CD6) ||
  1390. (ch >= 0x0D02 && ch <= 0x0D03) ||
  1391. (ch >= 0x0D3E && ch <= 0x0D43) ||
  1392. (ch >= 0x0D46 && ch <= 0x0D48) ||
  1393. (ch >= 0x0D4A && ch <= 0x0D4D) ||
  1394. (ch == 0x0D57) ||
  1395. (ch == 0x0E31) ||
  1396. (ch >= 0x0E34 && ch <= 0x0E3A) ||
  1397. (ch >= 0x0E47 && ch <= 0x0E4E) ||
  1398. (ch == 0x0EB1) ||
  1399. (ch >= 0x0EB4 && ch <= 0x0EB9) ||
  1400. (ch >= 0x0EBB && ch <= 0x0EBC) ||
  1401. (ch >= 0x0EC8 && ch <= 0x0ECD) ||
  1402. (ch >= 0x0F18 && ch <= 0x0F19) ||
  1403. (ch == 0x0F35) ||
  1404. (ch == 0x0F37) ||
  1405. (ch == 0x0F39) ||
  1406. (ch == 0x0F3E) ||
  1407. (ch == 0x0F3F) ||
  1408. (ch >= 0x0F71 && ch <= 0x0F84) ||
  1409. (ch >= 0x0F86 && ch <= 0x0F8B) ||
  1410. (ch >= 0x0F90 && ch <= 0x0F95) ||
  1411. (ch == 0x0F97) ||
  1412. (ch >= 0x0F99 && ch <= 0x0FAD) ||
  1413. (ch >= 0x0FB1 && ch <= 0x0FB7) ||
  1414. (ch == 0x0FB9) ||
  1415. (ch >= 0x20D0 && ch <= 0x20DC) ||
  1416. (ch == 0x20E1) ||
  1417. (ch >= 0x302A && ch <= 0x302F) ||
  1418. (ch == 0x3099) ||
  1419. (ch == 0x309A);
  1420. }
  1421. private static bool IsExtender (int ch)
  1422. {
  1423. return
  1424. (ch == 0x00B7) ||
  1425. (ch == 0x02D0) ||
  1426. (ch == 0x02D1) ||
  1427. (ch == 0x0387) ||
  1428. (ch == 0x0640) ||
  1429. (ch == 0x0E46) ||
  1430. (ch == 0x0EC6) ||
  1431. (ch == 0x3005) ||
  1432. (ch >= 0x3031 && ch <= 0x3035) ||
  1433. (ch >= 0x309D && ch <= 0x309E) ||
  1434. (ch >= 0x30FC && ch <= 0x30FE);
  1435. }
  1436. #endif
  1437. [Test]
  1438. public void IsName ()
  1439. {
  1440. Assertion.Assert (XmlReader.IsName ("foo"));
  1441. Assertion.Assert (!XmlReader.IsName ("1foo"));
  1442. Assertion.Assert (!XmlReader.IsName (" foo"));
  1443. }
  1444. [Test]
  1445. public void IsNameToken ()
  1446. {
  1447. Assertion.Assert (XmlReader.IsNameToken ("foo"));
  1448. Assertion.Assert (XmlReader.IsNameToken ("1foo"));
  1449. Assertion.Assert (!XmlReader.IsNameToken (" foo"));
  1450. }
  1451. [Test]
  1452. public void MoveToElementFromAttribute ()
  1453. {
  1454. string xml = @"<foo bar=""baz"" />";
  1455. XmlReader xmlReader =
  1456. new XmlTextReader (new StringReader (xml));
  1457. Assertion.Assert (xmlReader.Read ());
  1458. Assertion.AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
  1459. Assertion.Assert (xmlReader.MoveToFirstAttribute ());
  1460. Assertion.AssertEquals (XmlNodeType.Attribute, xmlReader.NodeType);
  1461. Assertion.Assert (xmlReader.MoveToElement ());
  1462. Assertion.AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
  1463. }
  1464. [Test]
  1465. public void MoveToElementFromElement ()
  1466. {
  1467. string xml = @"<foo bar=""baz"" />";
  1468. XmlReader xmlReader =
  1469. new XmlTextReader (new StringReader (xml));
  1470. Assertion.Assert (xmlReader.Read ());
  1471. Assertion.AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
  1472. Assertion.Assert (!xmlReader.MoveToElement ());
  1473. Assertion.AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
  1474. }
  1475. [Test]
  1476. public void MoveToFirstAttributeWithNoAttributes ()
  1477. {
  1478. string xml = @"<foo />";
  1479. XmlReader xmlReader =
  1480. new XmlTextReader (new StringReader (xml));
  1481. Assertion.Assert (xmlReader.Read ());
  1482. Assertion.AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
  1483. Assertion.Assert (!xmlReader.MoveToFirstAttribute ());
  1484. Assertion.AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
  1485. }
  1486. [Test]
  1487. public void MoveToNextAttributeWithNoAttributes ()
  1488. {
  1489. string xml = @"<foo />";
  1490. XmlReader xmlReader =
  1491. new XmlTextReader (new StringReader (xml));
  1492. Assertion.Assert (xmlReader.Read ());
  1493. Assertion.AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
  1494. Assertion.Assert (!xmlReader.MoveToNextAttribute ());
  1495. Assertion.AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
  1496. }
  1497. [Test]
  1498. public void MoveToNextAttribute()
  1499. {
  1500. string xml = @"<foo bar=""baz"" quux='quuux'/>";
  1501. XmlReader xmlReader =
  1502. new XmlTextReader (new StringReader (xml));
  1503. AssertStartDocument (xmlReader);
  1504. AssertNode (
  1505. xmlReader, // xmlReader
  1506. XmlNodeType.Element, // nodeType
  1507. 0, //depth
  1508. true, // isEmptyElement
  1509. "foo", // name
  1510. String.Empty, // prefix
  1511. "foo", // localName
  1512. String.Empty, // namespaceURI
  1513. String.Empty, // value
  1514. 2 // attributeCount
  1515. );
  1516. AssertAttribute (
  1517. xmlReader, // xmlReader
  1518. "bar", // name
  1519. String.Empty, // prefix
  1520. "bar", // localName
  1521. String.Empty, // namespaceURI
  1522. "baz" // value
  1523. );
  1524. AssertAttribute (
  1525. xmlReader, // xmlReader
  1526. "quux", // name
  1527. String.Empty, // prefix
  1528. "quux", // localName
  1529. String.Empty, // namespaceURI
  1530. "quuux" // value
  1531. );
  1532. Assertion.Assert (xmlReader.MoveToNextAttribute ());
  1533. Assertion.Assert ("bar" == xmlReader.Name || "quux" == xmlReader.Name);
  1534. Assertion.Assert ("baz" == xmlReader.Value || "quuux" == xmlReader.Value);
  1535. Assertion.Assert (xmlReader.MoveToNextAttribute ());
  1536. Assertion.Assert ("bar" == xmlReader.Name || "quux" == xmlReader.Name);
  1537. Assertion.Assert ("baz" == xmlReader.Value || "quuux" == xmlReader.Value);
  1538. Assertion.Assert (!xmlReader.MoveToNextAttribute ());
  1539. Assertion.Assert (xmlReader.MoveToElement ());
  1540. AssertNodeValues (
  1541. xmlReader, // xmlReader
  1542. XmlNodeType.Element, // nodeType
  1543. 0, //depth
  1544. true, // isEmptyElement
  1545. "foo", // name
  1546. String.Empty, // prefix
  1547. "foo", // localName
  1548. String.Empty, // namespaceURI
  1549. String.Empty, // value
  1550. 2 // attributeCount
  1551. );
  1552. AssertEndDocument (xmlReader);
  1553. }
  1554. [Test]
  1555. public void AttributeOrder ()
  1556. {
  1557. string xml = @"<foo _1='1' _2='2' _3='3' />";
  1558. XmlReader xmlReader =
  1559. new XmlTextReader (new StringReader (xml));
  1560. Assertion.Assert (xmlReader.Read ());
  1561. Assertion.AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
  1562. Assertion.Assert (xmlReader.MoveToFirstAttribute ());
  1563. Assertion.AssertEquals ("_1", xmlReader.Name);
  1564. Assertion.Assert (xmlReader.MoveToNextAttribute ());
  1565. Assertion.AssertEquals ("_2", xmlReader.Name);
  1566. Assertion.Assert (xmlReader.MoveToNextAttribute ());
  1567. Assertion.AssertEquals ("_3", xmlReader.Name);
  1568. Assertion.Assert (!xmlReader.MoveToNextAttribute ());
  1569. }
  1570. [Test]
  1571. public void FragmentConstructor()
  1572. {
  1573. XmlDocument doc = new XmlDocument();
  1574. // doc.LoadXml("<root/>");
  1575. string xml = @"<foo><bar xmlns=""NSURI"">TEXT NODE</bar></foo>";
  1576. MemoryStream ms = new MemoryStream(Encoding.Default.GetBytes(xml));
  1577. XmlParserContext ctx = new XmlParserContext(doc.NameTable, new XmlNamespaceManager(doc.NameTable), "", "", "", "",
  1578. doc.BaseURI, "", XmlSpace.Default, Encoding.Default);
  1579. XmlTextReader xmlReader = new XmlTextReader(ms, XmlNodeType.Element, ctx);
  1580. AssertNode(xmlReader, XmlNodeType.Element, 0, false, "foo", "", "foo", "", "", 0);
  1581. AssertNode(xmlReader, XmlNodeType.Element, 1, false, "bar", "", "bar", "NSURI", "", 1);
  1582. AssertNode(xmlReader, XmlNodeType.Text, 2, false, "", "", "", "NSURI", "TEXT NODE", 0);
  1583. AssertNode(xmlReader, XmlNodeType.EndElement, 1, false, "bar", "", "bar", "NSURI", "", 0);
  1584. AssertNode(xmlReader, XmlNodeType.EndElement, 0, false, "foo", "", "foo", "", "", 0);
  1585. AssertEndDocument (xmlReader);
  1586. }
  1587. [Test]
  1588. public void AttributeWithCharacterReference ()
  1589. {
  1590. string xml = @"<a value='hello &amp; world' />";
  1591. XmlReader xmlReader =
  1592. new XmlTextReader (new StringReader (xml));
  1593. xmlReader.Read ();
  1594. Assertion.AssertEquals ("hello & world", xmlReader ["value"]);
  1595. }
  1596. [Test]
  1597. public void AttributeWithEntityReference ()
  1598. {
  1599. string xml = @"<a value='hello &ent; world' />";
  1600. XmlReader xmlReader =
  1601. new XmlTextReader (new StringReader (xml));
  1602. xmlReader.Read ();
  1603. xmlReader.MoveToFirstAttribute ();
  1604. xmlReader.ReadAttributeValue ();
  1605. Assertion.AssertEquals ("hello ", xmlReader.Value);
  1606. xmlReader.ReadAttributeValue ();
  1607. Assertion.AssertEquals (XmlNodeType.EntityReference, xmlReader.NodeType);
  1608. Assertion.AssertEquals ("ent", xmlReader.Name);
  1609. Assertion.AssertEquals (XmlNodeType.EntityReference, xmlReader.NodeType);
  1610. xmlReader.ReadAttributeValue ();
  1611. Assertion.AssertEquals (" world", xmlReader.Value);
  1612. Assertion.AssertEquals (XmlNodeType.Text, xmlReader.NodeType);
  1613. xmlReader.ReadAttributeValue ();
  1614. Assertion.AssertEquals (XmlNodeType.None, xmlReader.NodeType);
  1615. xmlReader.ReadAttributeValue ();
  1616. Assertion.AssertEquals (XmlNodeType.None, xmlReader.NodeType);
  1617. }
  1618. [Test]
  1619. public void QuoteChar ()
  1620. {
  1621. string xml = @"<a value='hello &amp; world' value2="""" />";
  1622. XmlReader xmlReader =
  1623. new XmlTextReader (new StringReader (xml));
  1624. xmlReader.Read ();
  1625. xmlReader.MoveToFirstAttribute ();
  1626. Assertion.AssertEquals ("First", '\'', xmlReader.QuoteChar);
  1627. xmlReader.MoveToNextAttribute ();
  1628. Assertion.AssertEquals ("Next", '"', xmlReader.QuoteChar);
  1629. xmlReader.MoveToFirstAttribute ();
  1630. Assertion.AssertEquals ("First.Again", '\'', xmlReader.QuoteChar);
  1631. }
  1632. }
  1633. }