XmlTextReaderTests.cs 38 KB

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