XmlNodeReaderImpl.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820
  1. //
  2. // System.Xml.XmlNodeReaderImpl.cs - implements the core part of XmlNodeReader
  3. //
  4. // Author:
  5. // Atsushi Enomoto ([email protected])
  6. //
  7. // (C) 2004 Novell Inc.
  8. //
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. //
  30. // This serves the implementation part of XmlNodeReader except for
  31. // ResolveEntity().
  32. //
  33. using System;
  34. #if NET_2_0
  35. using System.Collections.Generic;
  36. #endif
  37. using System.Xml;
  38. using System.Text;
  39. using Mono.Xml;
  40. #if NET_2_0
  41. using System.Xml.Schema;
  42. #endif
  43. namespace System.Xml
  44. {
  45. #if NET_2_0
  46. internal class XmlNodeReaderImpl : XmlReader, IHasXmlParserContext, IXmlNamespaceResolver
  47. #else
  48. internal class XmlNodeReaderImpl : XmlReader, IHasXmlParserContext
  49. #endif
  50. {
  51. XmlDocument document;
  52. XmlNode startNode;
  53. XmlNode current;
  54. XmlNode ownerLinkedNode;
  55. ReadState state = ReadState.Initial;
  56. int depth;
  57. bool isEndElement;
  58. bool ignoreStartNode;
  59. #region Constructor
  60. internal XmlNodeReaderImpl (XmlNodeReaderImpl entityContainer)
  61. : this (entityContainer.current)
  62. {
  63. }
  64. public XmlNodeReaderImpl (XmlNode node)
  65. {
  66. startNode = node;
  67. depth = 0;
  68. document = startNode.NodeType == XmlNodeType.Document ?
  69. startNode as XmlDocument : startNode.OwnerDocument;
  70. switch (node.NodeType) {
  71. case XmlNodeType.Document:
  72. case XmlNodeType.DocumentFragment:
  73. case XmlNodeType.EntityReference:
  74. ignoreStartNode = true;
  75. break;
  76. }
  77. }
  78. #endregion
  79. #region Properties
  80. public override int AttributeCount {
  81. get {
  82. if (state != ReadState.Interactive)
  83. return 0;
  84. if (isEndElement || current == null)
  85. return 0;
  86. XmlNode n = ownerLinkedNode;
  87. return n.Attributes != null ? n.Attributes.Count : 0;
  88. }
  89. }
  90. public override string BaseURI {
  91. get {
  92. if (current == null)
  93. return startNode.BaseURI;
  94. return current.BaseURI;
  95. }
  96. }
  97. #if NET_2_0
  98. public override bool CanReadBinaryContent {
  99. get { return true; }
  100. }
  101. public override bool CanReadValueChunk {
  102. get { return true; }
  103. }
  104. #else
  105. internal override bool CanReadBinaryContent {
  106. get { return true; }
  107. }
  108. internal override bool CanReadValueChunk {
  109. get { return true; }
  110. }
  111. #endif
  112. public override bool CanResolveEntity {
  113. get { return false; }
  114. }
  115. public override int Depth {
  116. get {
  117. return current == null ? 0 :
  118. current == ownerLinkedNode ? depth :
  119. current.NodeType == XmlNodeType.Attribute ? depth + 1 :
  120. depth + 2;
  121. }
  122. }
  123. public override bool EOF {
  124. get { return state == ReadState.EndOfFile || state == ReadState.Error; }
  125. }
  126. public override bool HasAttributes {
  127. get {
  128. if (isEndElement || current == null)
  129. return false;
  130. // MS BUG: inconsistent return value between XmlTextReader and XmlNodeReader.
  131. // As for attribute and its descendants, XmlReader returns element's HasAttributes.
  132. XmlNode n = ownerLinkedNode;
  133. if (n.Attributes == null ||
  134. n.Attributes.Count == 0)
  135. return false;
  136. else
  137. return true;
  138. }
  139. }
  140. public override bool HasValue {
  141. get {
  142. if (current == null)
  143. return false;
  144. switch (current.NodeType) {
  145. case XmlNodeType.Element:
  146. case XmlNodeType.EntityReference:
  147. case XmlNodeType.Document:
  148. case XmlNodeType.DocumentFragment:
  149. case XmlNodeType.Notation:
  150. case XmlNodeType.EndElement:
  151. case XmlNodeType.EndEntity:
  152. return false;
  153. default:
  154. return true;
  155. }
  156. }
  157. }
  158. public override bool IsDefault {
  159. get {
  160. if (current == null)
  161. return false;
  162. if (current.NodeType != XmlNodeType.Attribute)
  163. return false;
  164. else
  165. {
  166. return !((XmlAttribute) current).Specified;
  167. }
  168. }
  169. }
  170. public override bool IsEmptyElement {
  171. get {
  172. if (current == null)
  173. return false;
  174. if(current.NodeType == XmlNodeType.Element)
  175. return ((XmlElement) current).IsEmpty;
  176. else
  177. return false;
  178. }
  179. }
  180. #if NET_2_0
  181. #else
  182. public override string this [int i] {
  183. get { return GetAttribute (i); }
  184. }
  185. public override string this [string name] {
  186. get { return GetAttribute (name); }
  187. }
  188. public override string this [string name, string namespaceURI] {
  189. get { return GetAttribute (name, namespaceURI); }
  190. }
  191. #endif
  192. public override string LocalName {
  193. get {
  194. if (current == null)
  195. return String.Empty;
  196. switch (current.NodeType) {
  197. case XmlNodeType.Attribute:
  198. case XmlNodeType.DocumentType:
  199. case XmlNodeType.Element:
  200. case XmlNodeType.EntityReference:
  201. case XmlNodeType.ProcessingInstruction:
  202. case XmlNodeType.XmlDeclaration:
  203. return current.LocalName;
  204. }
  205. return String.Empty;
  206. }
  207. }
  208. public override string Name {
  209. get {
  210. if (current == null)
  211. return String.Empty;
  212. switch (current.NodeType) {
  213. case XmlNodeType.Attribute:
  214. case XmlNodeType.DocumentType:
  215. case XmlNodeType.Element:
  216. case XmlNodeType.EntityReference:
  217. case XmlNodeType.ProcessingInstruction:
  218. case XmlNodeType.XmlDeclaration:
  219. return current.Name;
  220. }
  221. return String.Empty;
  222. }
  223. }
  224. public override string NamespaceURI {
  225. get {
  226. if (current == null)
  227. return String.Empty;
  228. return current.NamespaceURI;
  229. }
  230. }
  231. public override XmlNameTable NameTable {
  232. get { return document.NameTable; }
  233. }
  234. public override XmlNodeType NodeType {
  235. get {
  236. if (current == null)
  237. return XmlNodeType.None;
  238. return isEndElement ? XmlNodeType.EndElement : current.NodeType;
  239. }
  240. }
  241. public override string Prefix {
  242. get {
  243. if (current == null)
  244. return String.Empty;
  245. return current.Prefix;
  246. }
  247. }
  248. #if NET_2_0
  249. #else
  250. public override char QuoteChar {
  251. get {
  252. return '"';
  253. }
  254. }
  255. #endif
  256. public override ReadState ReadState {
  257. get { return state; }
  258. }
  259. #if NET_2_0
  260. public override IXmlSchemaInfo SchemaInfo {
  261. get { return current != null ? current.SchemaInfo : null; }
  262. }
  263. #endif
  264. public override string Value {
  265. get {
  266. if (NodeType == XmlNodeType.DocumentType)
  267. return ((XmlDocumentType) current).InternalSubset;
  268. else
  269. return HasValue ? current.Value : String.Empty;
  270. }
  271. }
  272. public override string XmlLang {
  273. get {
  274. if (current == null)
  275. return startNode.XmlLang;
  276. return current.XmlLang;
  277. }
  278. }
  279. public override XmlSpace XmlSpace {
  280. get {
  281. if (current == null)
  282. return startNode.XmlSpace;
  283. return current.XmlSpace;
  284. }
  285. }
  286. #endregion
  287. #region Methods
  288. public override void Close ()
  289. {
  290. current = null;
  291. state = ReadState.Closed;
  292. }
  293. public override string GetAttribute (int attributeIndex)
  294. {
  295. if (NodeType == XmlNodeType.XmlDeclaration) {
  296. XmlDeclaration decl = current as XmlDeclaration;
  297. if (attributeIndex == 0)
  298. return decl.Version;
  299. else if (attributeIndex == 1) {
  300. if (decl.Encoding != String.Empty)
  301. return decl.Encoding;
  302. else if (decl.Standalone != String.Empty)
  303. return decl.Standalone;
  304. }
  305. else if (attributeIndex == 2 &&
  306. decl.Encoding != String.Empty && decl.Standalone != null)
  307. return decl.Standalone;
  308. throw new ArgumentOutOfRangeException ("Index out of range.");
  309. } else if (NodeType == XmlNodeType.DocumentType) {
  310. XmlDocumentType doctype = current as XmlDocumentType;
  311. if (attributeIndex == 0) {
  312. if (doctype.PublicId != "")
  313. return doctype.PublicId;
  314. else if (doctype.SystemId != "")
  315. return doctype.SystemId;
  316. } else if (attributeIndex == 1)
  317. if (doctype.PublicId == "" && doctype.SystemId != "")
  318. return doctype.SystemId;
  319. throw new ArgumentOutOfRangeException ("Index out of range.");
  320. }
  321. // This is MS.NET bug which returns attributes in spite of EndElement.
  322. if (isEndElement || current == null)
  323. return null;
  324. if (attributeIndex < 0 || attributeIndex > AttributeCount)
  325. throw new ArgumentOutOfRangeException ("Index out of range.");
  326. return ownerLinkedNode.Attributes [attributeIndex].Value;
  327. }
  328. public override string GetAttribute (string name)
  329. {
  330. // This is MS.NET bug which returns attributes in spite of EndElement.
  331. if (isEndElement || current == null)
  332. return null;
  333. if (NodeType == XmlNodeType.XmlDeclaration)
  334. return GetXmlDeclarationAttribute (name);
  335. else if (NodeType == XmlNodeType.DocumentType)
  336. return GetDocumentTypeAttribute (name);
  337. if (ownerLinkedNode.Attributes == null)
  338. return null;
  339. XmlAttribute attr = ownerLinkedNode.Attributes [name];
  340. if (attr == null)
  341. return null;
  342. else
  343. return attr.Value;
  344. }
  345. public override string GetAttribute (string name, string namespaceURI)
  346. {
  347. // This is MS.NET bug which returns attributes in spite of EndElement.
  348. if (isEndElement || current == null)
  349. return null;
  350. if (NodeType == XmlNodeType.XmlDeclaration)
  351. return GetXmlDeclarationAttribute (name);
  352. else if (NodeType == XmlNodeType.DocumentType)
  353. return GetDocumentTypeAttribute (name);
  354. if (ownerLinkedNode.Attributes == null)
  355. return null;
  356. XmlAttribute attr = ownerLinkedNode.Attributes [name, namespaceURI];
  357. if (attr == null)
  358. return null; // In fact MS.NET returns null instead of String.Empty.
  359. else
  360. return attr.Value;
  361. }
  362. private string GetXmlDeclarationAttribute (string name)
  363. {
  364. XmlDeclaration decl = current as XmlDeclaration;
  365. switch (name) {
  366. case "version":
  367. return decl.Version;
  368. case "encoding":
  369. // This is MS.NET bug that XmlNodeReturns in case of string.empty.
  370. return decl.Encoding != String.Empty ? decl.Encoding : null;
  371. case "standalone":
  372. return decl.Standalone;
  373. }
  374. return null;
  375. }
  376. private string GetDocumentTypeAttribute (string name)
  377. {
  378. XmlDocumentType doctype = current as XmlDocumentType;
  379. switch (name) {
  380. case "PUBLIC":
  381. return doctype.PublicId;
  382. case "SYSTEM":
  383. return doctype.SystemId;
  384. }
  385. return null;
  386. }
  387. XmlParserContext IHasXmlParserContext.ParserContext {
  388. get {
  389. return new XmlParserContext (document.NameTable,
  390. current == null ?
  391. new XmlNamespaceManager (document.NameTable) :
  392. current.ConstructNamespaceManager (),
  393. document.DocumentType != null ? document.DocumentType.DTD : null,
  394. current == null ? document.BaseURI : current.BaseURI,
  395. XmlLang, XmlSpace, Encoding.Unicode);
  396. }
  397. }
  398. #if NET_2_0
  399. public IDictionary<string, string> GetNamespacesInScope (XmlNamespaceScope scope)
  400. {
  401. IDictionary<string, string> table = new Dictionary<string, string> ();
  402. XmlNode n = current;
  403. do {
  404. if (n.NodeType == XmlNodeType.Document)
  405. break;
  406. for (int i = 0; i < current.Attributes.Count; i++) {
  407. XmlAttribute a = current.Attributes [i];
  408. if (a.NamespaceURI == XmlNamespaceManager.XmlnsXmlns)
  409. table.Add (a.Prefix == XmlNamespaceManager.PrefixXmlns ? a.LocalName : String.Empty, a.Value);
  410. }
  411. if (scope == XmlNamespaceScope.Local)
  412. return table;
  413. n = n.ParentNode;
  414. } while (n != null);
  415. if (scope == XmlNamespaceScope.All)
  416. table.Add (XmlNamespaceManager.PrefixXml, XmlNamespaceManager.XmlnsXml);
  417. return table;
  418. }
  419. #endif
  420. private XmlElement GetCurrentElement ()
  421. {
  422. XmlElement el = null;
  423. switch (current.NodeType) {
  424. case XmlNodeType.Attribute:
  425. el = ((XmlAttribute) current).OwnerElement;
  426. break;
  427. case XmlNodeType.Element:
  428. el = (XmlElement) current;
  429. break;
  430. case XmlNodeType.Text:
  431. case XmlNodeType.CDATA:
  432. case XmlNodeType.EntityReference:
  433. case XmlNodeType.Comment:
  434. case XmlNodeType.SignificantWhitespace:
  435. case XmlNodeType.Whitespace:
  436. case XmlNodeType.ProcessingInstruction:
  437. el = current.ParentNode as XmlElement;
  438. break;
  439. }
  440. return el;
  441. }
  442. public override string LookupNamespace (string prefix)
  443. {
  444. if (current == null)
  445. return null;
  446. XmlElement el = GetCurrentElement ();
  447. for (; el != null; el = el.ParentNode as XmlElement) {
  448. for (int i = 0; i < el.Attributes.Count; i++) {
  449. XmlAttribute attr = el.Attributes [i];
  450. if (attr.NamespaceURI != XmlNamespaceManager.XmlnsXmlns)
  451. continue;
  452. if (prefix == "") {
  453. if (attr.Prefix == "")
  454. return attr.Value;
  455. }
  456. else if (attr.LocalName == prefix)
  457. return attr.Value;
  458. continue;
  459. }
  460. }
  461. switch (prefix) {
  462. case XmlNamespaceManager.PrefixXml:
  463. return XmlNamespaceManager.XmlnsXml;
  464. case XmlNamespaceManager.PrefixXmlns:
  465. return XmlNamespaceManager.XmlnsXmlns;
  466. }
  467. return null;
  468. }
  469. #if NET_2_0
  470. public string LookupPrefix (string ns)
  471. {
  472. return LookupPrefix (ns, false);
  473. }
  474. public string LookupPrefix (string ns, bool atomizedNames)
  475. {
  476. if (current == null)
  477. return null;
  478. XmlElement el = GetCurrentElement ();
  479. for (; el != null; el = el.ParentNode as XmlElement) {
  480. for (int i = 0; i < el.Attributes.Count; i++) {
  481. XmlAttribute attr = el.Attributes [i];
  482. if (atomizedNames) {
  483. if (!Object.ReferenceEquals (attr.NamespaceURI, XmlNamespaceManager.XmlnsXmlns))
  484. continue;
  485. if (Object.ReferenceEquals (attr.Value, ns))
  486. // xmlns:blah="..." -> LocalName, xmlns="..." -> String.Empty
  487. return attr.Prefix != String.Empty ? attr.LocalName : String.Empty;
  488. } else {
  489. if (attr.NamespaceURI != XmlNamespaceManager.XmlnsXmlns)
  490. continue;
  491. if (attr.Value == ns)
  492. // xmlns:blah="..." -> LocalName, xmlns="..." -> String.Empty
  493. return attr.Prefix != String.Empty ? attr.LocalName : String.Empty;
  494. }
  495. }
  496. }
  497. switch (ns) {
  498. case XmlNamespaceManager.XmlnsXml:
  499. return XmlNamespaceManager.PrefixXml;
  500. case XmlNamespaceManager.XmlnsXmlns:
  501. return XmlNamespaceManager.PrefixXmlns;
  502. }
  503. return null;
  504. }
  505. #endif
  506. public override void MoveToAttribute (int attributeIndex)
  507. {
  508. if (isEndElement || attributeIndex < 0 || attributeIndex > AttributeCount)
  509. throw new ArgumentOutOfRangeException ();
  510. state = ReadState.Interactive;
  511. current = ownerLinkedNode.Attributes [attributeIndex];
  512. }
  513. public override bool MoveToAttribute (string name)
  514. {
  515. if (isEndElement || current == null)
  516. return false;
  517. XmlNode tmpCurrent = current;
  518. if (current.ParentNode.NodeType == XmlNodeType.Attribute)
  519. current = current.ParentNode;
  520. if (ownerLinkedNode.Attributes == null)
  521. return false;
  522. XmlAttribute attr = ownerLinkedNode.Attributes [name];
  523. if (attr == null) {
  524. current = tmpCurrent;
  525. return false;
  526. }
  527. else {
  528. current = attr;
  529. return true;
  530. }
  531. }
  532. public override bool MoveToAttribute (string name, string namespaceURI)
  533. {
  534. if (isEndElement || current == null)
  535. return false;
  536. if (ownerLinkedNode.Attributes == null)
  537. return false;
  538. XmlAttribute attr = ownerLinkedNode.Attributes [name, namespaceURI];
  539. if (attr == null)
  540. return false;
  541. else {
  542. current = attr;
  543. return true;
  544. }
  545. }
  546. public override bool MoveToElement ()
  547. {
  548. if (current == null)
  549. return false;
  550. XmlNode n = ownerLinkedNode;
  551. if (current != n) {
  552. current = n;
  553. return true;
  554. } else
  555. return false;
  556. }
  557. public override bool MoveToFirstAttribute ()
  558. {
  559. if (current == null)
  560. return false;
  561. if (ownerLinkedNode.Attributes == null)
  562. return false;
  563. if(ownerLinkedNode.Attributes.Count > 0)
  564. {
  565. current = ownerLinkedNode.Attributes [0];
  566. return true;
  567. }
  568. else
  569. return false;
  570. }
  571. public override bool MoveToNextAttribute ()
  572. {
  573. if (current == null)
  574. return false;
  575. if (current.NodeType != XmlNodeType.Attribute)
  576. return MoveToFirstAttribute ();
  577. else
  578. {
  579. XmlAttributeCollection ac = ((XmlAttribute) current).OwnerElement.Attributes;
  580. for (int i=0; i<ac.Count-1; i++)
  581. {
  582. XmlAttribute attr = ac [i];
  583. if (attr == current)
  584. {
  585. i++;
  586. if (i == ac.Count)
  587. return false;
  588. current = ac [i];
  589. return true;
  590. }
  591. }
  592. return false;
  593. }
  594. }
  595. public override bool Read ()
  596. {
  597. // FIXME: at some stage inlining might work effectively.
  598. // if (EOF)
  599. if (state == ReadState.EndOfFile || state == ReadState.Error)
  600. return false;
  601. #if NET_2_0
  602. if (Binary != null)
  603. Binary.Reset ();
  604. #endif
  605. bool ret = ReadContent ();
  606. ownerLinkedNode = current;
  607. return ret;
  608. }
  609. bool ReadContent ()
  610. {
  611. if (ReadState == ReadState.Initial) {
  612. current = startNode;
  613. state = ReadState.Interactive;
  614. // when startNode is document or fragment
  615. if (ignoreStartNode)
  616. current = startNode.FirstChild;
  617. if (current == null) {
  618. state = ReadState.Error;
  619. return false;
  620. } else
  621. return true;
  622. }
  623. MoveToElement ();
  624. // don't step into EntityReference's children. Also
  625. // avoid re-entering children of already-consumed
  626. // element (i.e. when it is regarded as EndElement).
  627. XmlNode firstChild =
  628. !isEndElement && current.NodeType != XmlNodeType.EntityReference ?
  629. current.FirstChild : null;
  630. if (firstChild != null) {
  631. isEndElement = false;
  632. current = firstChild;
  633. depth++;
  634. return true;
  635. }
  636. if (current == startNode) { // Currently it is on the start node.
  637. if (IsEmptyElement || isEndElement) {
  638. // The start node is already consumed.
  639. isEndElement = false;
  640. current = null;
  641. state = ReadState.EndOfFile;
  642. return false;
  643. } else {
  644. // The start node is the only element
  645. // which should be processed. Now it
  646. // is set as EndElement.
  647. isEndElement = true;
  648. return true;
  649. }
  650. }
  651. if (!isEndElement && !IsEmptyElement &&
  652. current.NodeType == XmlNodeType.Element) {
  653. // element, currently not EndElement, and has
  654. // no child. (such as <foo></foo>, which
  655. // should become EndElement).
  656. isEndElement = true;
  657. return true;
  658. }
  659. // If NextSibling is available, move to there.
  660. XmlNode next = current.NextSibling;
  661. if (next != null) {
  662. isEndElement = false;
  663. current = next;
  664. return true;
  665. }
  666. // Otherwise, parent.
  667. XmlNode parent = current.ParentNode;
  668. if (parent == null || parent == startNode && ignoreStartNode) {
  669. // Parent is not available, or reached to
  670. // the start node. This reader never sets
  671. // startNode as current if it was originally
  672. // ignored (e.g. startNode is XmlDocument).
  673. isEndElement = false;
  674. current = null;
  675. state = ReadState.EndOfFile;
  676. return false;
  677. } else {
  678. // Parent was available, so return it as
  679. // EndElement.
  680. current = parent;
  681. depth--;
  682. isEndElement = true;
  683. return true;
  684. }
  685. }
  686. public override bool ReadAttributeValue ()
  687. {
  688. if (current.NodeType == XmlNodeType.Attribute) {
  689. if (current.FirstChild == null)
  690. return false;
  691. current = current.FirstChild;
  692. return true;
  693. } else if (current.ParentNode.NodeType == XmlNodeType.Attribute) {
  694. if (current.NextSibling == null)
  695. return false;
  696. current = current.NextSibling;
  697. return true;
  698. } else
  699. return false;
  700. }
  701. public override string ReadString ()
  702. {
  703. return base.ReadString ();
  704. }
  705. public override void ResolveEntity ()
  706. {
  707. throw new NotSupportedException ("Should not happen.");
  708. }
  709. public override void Skip ()
  710. {
  711. // Why is this overriden? Such skipping might raise
  712. // (or ignore) unexpected validation error.
  713. base.Skip ();
  714. }
  715. #endregion
  716. }
  717. }