XmlDocumentNavigator.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. //
  2. // System.Xml.XmlDocumentNavigator
  3. //
  4. // Authors:
  5. // Jason Diamond <[email protected]>
  6. // Atsushi Enomoto <[email protected]>
  7. //
  8. // (C) 2002 Jason Diamond
  9. // (C) 2003 Atsushi Enomoto
  10. //
  11. //
  12. // Permission is hereby granted, free of charge, to any person obtaining
  13. // a copy of this software and associated documentation files (the
  14. // "Software"), to deal in the Software without restriction, including
  15. // without limitation the rights to use, copy, modify, merge, publish,
  16. // distribute, sublicense, and/or sell copies of the Software, and to
  17. // permit persons to whom the Software is furnished to do so, subject to
  18. // the following conditions:
  19. //
  20. // The above copyright notice and this permission notice shall be
  21. // included in all copies or substantial portions of the Software.
  22. //
  23. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  27. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  28. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  29. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  30. //
  31. using System;
  32. using System.Collections;
  33. using System.Xml;
  34. using System.Xml.XPath;
  35. namespace System.Xml
  36. {
  37. internal class XmlDocumentNavigator : XPathNavigator, IHasXmlNode
  38. {
  39. #region Constructors
  40. internal XmlDocumentNavigator (XmlNode node)
  41. : this (node, null)
  42. {
  43. nsNodeXml = document.CreateAttribute ("xmlns", "xml", Xmlns);
  44. nsNodeXml.Value = XmlnsXML;
  45. if (node.NodeType == XmlNodeType.Attribute && node.NamespaceURI == XmlNamespaceManager.XmlnsXmlns) {
  46. nsNode = (XmlAttribute) node;
  47. node = nsNode.OwnerElement;
  48. }
  49. }
  50. private XmlDocumentNavigator (XmlNode node, XmlAttribute nsNodeXml)
  51. {
  52. this.node = node;
  53. this.document = node.NodeType == XmlNodeType.Document ?
  54. node as XmlDocument : node.OwnerDocument;
  55. this.nsNodeXml = nsNodeXml;
  56. }
  57. #endregion
  58. #region Fields
  59. private const string Xmlns = "http://www.w3.org/2000/xmlns/";
  60. private const string XmlnsXML = "http://www.w3.org/XML/1998/namespace";
  61. private XmlAttribute nsNodeXml;
  62. private XmlNode node;
  63. private XmlDocument document;
  64. // Current namespace node (ancestor's attribute of current node).
  65. private XmlAttribute nsNode;
  66. private ArrayList iteratedNsNames;
  67. #endregion
  68. #region Properties
  69. public override string BaseURI {
  70. get {
  71. return node.BaseURI;
  72. }
  73. }
  74. public override bool HasAttributes {
  75. get {
  76. if (NsNode != null)
  77. return false;
  78. if (node.Attributes != null)
  79. for (int i = 0; i < node.Attributes.Count; i++)
  80. if (node.Attributes [i].NamespaceURI != Xmlns)
  81. return true;
  82. return false;
  83. }
  84. }
  85. public override bool HasChildren {
  86. get {
  87. if (NsNode != null)
  88. return false;
  89. XPathNodeType nodeType = NodeType;
  90. bool canHaveChildren = nodeType == XPathNodeType.Root || nodeType == XPathNodeType.Element;
  91. return canHaveChildren && GetFirstChild (node) != null;
  92. }
  93. }
  94. public override bool IsEmptyElement {
  95. get {
  96. if (NsNode != null)
  97. return false;
  98. return node.NodeType == XmlNodeType.Element
  99. && ((XmlElement) node).IsEmpty;
  100. }
  101. }
  102. public XmlAttribute NsNode {
  103. get { return nsNode; }
  104. set {
  105. if (value == null)
  106. iteratedNsNames = null;
  107. else
  108. {
  109. if (iteratedNsNames == null)
  110. iteratedNsNames = new ArrayList();
  111. else
  112. {
  113. if (iteratedNsNames.IsReadOnly)
  114. iteratedNsNames = new ArrayList(iteratedNsNames);
  115. }
  116. iteratedNsNames.Add (value.Name);
  117. }
  118. nsNode = value;
  119. }
  120. }
  121. public override string LocalName {
  122. get {
  123. XmlAttribute nsNode = NsNode;
  124. if (nsNode != null) {
  125. if (nsNode == nsNodeXml)
  126. return "xml";
  127. else
  128. return (nsNode.Name == "xmlns") ? String.Empty : nsNode.LocalName;
  129. }
  130. XPathNodeType nodeType = NodeType;
  131. bool canHaveName =
  132. nodeType == XPathNodeType.Element ||
  133. nodeType == XPathNodeType.Attribute ||
  134. nodeType == XPathNodeType.ProcessingInstruction ||
  135. nodeType == XPathNodeType.Namespace;
  136. return canHaveName ? node.LocalName : String.Empty;
  137. }
  138. }
  139. public override string Name {
  140. get {
  141. if (NsNode != null)
  142. return LocalName;
  143. XPathNodeType nodeType = NodeType;
  144. bool canHaveName =
  145. nodeType == XPathNodeType.Element ||
  146. nodeType == XPathNodeType.Attribute ||
  147. nodeType == XPathNodeType.ProcessingInstruction ||
  148. nodeType == XPathNodeType.Namespace;
  149. return canHaveName ? node.Name : String.Empty;
  150. }
  151. }
  152. public override string NamespaceURI {
  153. get { return (NsNode != null) ? String.Empty : node.NamespaceURI; }
  154. }
  155. public override XmlNameTable NameTable {
  156. get {
  157. return document.NameTable;
  158. }
  159. }
  160. public override XPathNodeType NodeType {
  161. get {
  162. if (NsNode != null)
  163. return XPathNodeType.Namespace;
  164. XmlNode n = node;
  165. bool sw = false;
  166. do {
  167. switch (n.NodeType) {
  168. case XmlNodeType.SignificantWhitespace:
  169. sw = true;
  170. n = GetNextSibling (n);
  171. break;
  172. case XmlNodeType.Whitespace:
  173. n = GetNextSibling (n);
  174. break;
  175. case XmlNodeType.Text:
  176. case XmlNodeType.CDATA:
  177. return XPathNodeType.Text;
  178. default:
  179. n = null;
  180. break;
  181. }
  182. } while (n != null);
  183. return sw ?
  184. XPathNodeType.SignificantWhitespace :
  185. node.XPathNodeType;
  186. }
  187. }
  188. public override string Prefix {
  189. get { return (NsNode != null) ? String.Empty : node.Prefix; }
  190. }
  191. public override string Value {
  192. get {
  193. switch (NodeType) {
  194. case XPathNodeType.Attribute:
  195. case XPathNodeType.Comment:
  196. case XPathNodeType.ProcessingInstruction:
  197. return node.Value;
  198. case XPathNodeType.Text:
  199. case XPathNodeType.Whitespace:
  200. case XPathNodeType.SignificantWhitespace:
  201. string value = node.Value;
  202. for (XmlNode n = GetNextSibling (node); n != null; n = GetNextSibling (n)) {
  203. switch (n.XPathNodeType) {
  204. case XPathNodeType.Text:
  205. case XPathNodeType.Whitespace:
  206. case XPathNodeType.SignificantWhitespace:
  207. value += n.Value;
  208. continue;
  209. }
  210. break;
  211. }
  212. return value;
  213. case XPathNodeType.Element:
  214. case XPathNodeType.Root:
  215. return node.InnerText;
  216. case XPathNodeType.Namespace:
  217. return NsNode == nsNodeXml ? XmlnsXML : NsNode.Value;
  218. }
  219. return String.Empty;
  220. }
  221. }
  222. public override string XmlLang {
  223. get {
  224. return node.XmlLang;
  225. }
  226. }
  227. #endregion
  228. #region Methods
  229. private bool CheckNsNameAppearance (string name, string ns)
  230. {
  231. if (iteratedNsNames != null && iteratedNsNames.Contains (name))
  232. return true;
  233. // default namespace erasure - just add name and never return this node
  234. if (ns == String.Empty) {
  235. if (iteratedNsNames == null)
  236. iteratedNsNames = new ArrayList();
  237. else
  238. {
  239. if (iteratedNsNames.IsReadOnly)
  240. iteratedNsNames = new ArrayList(iteratedNsNames);
  241. }
  242. iteratedNsNames.Add ("xmlns");
  243. return true;
  244. }
  245. return false;
  246. }
  247. public override XPathNavigator Clone ()
  248. {
  249. XmlDocumentNavigator clone = new XmlDocumentNavigator (node, nsNodeXml);
  250. clone.nsNode = nsNode;
  251. clone.iteratedNsNames = (iteratedNsNames == null || iteratedNsNames.IsReadOnly) ? iteratedNsNames : ArrayList.ReadOnly(iteratedNsNames);
  252. return clone;
  253. }
  254. public override string GetAttribute (string localName, string namespaceURI)
  255. {
  256. if (HasAttributes) {
  257. XmlElement el = Node as XmlElement;
  258. return el != null ? el.GetAttribute (localName, namespaceURI) : String.Empty;
  259. }
  260. return String.Empty;
  261. }
  262. public override string GetNamespace (string name)
  263. {
  264. // MSDN says "String.Empty if a matching namespace
  265. // node is not found or if the navigator is not
  266. // positioned on an element node", but in fact it
  267. // returns actual namespace for the other nodes.
  268. return Node.GetNamespaceOfPrefix (name);
  269. }
  270. public override bool IsDescendant (XPathNavigator other)
  271. {
  272. if (NsNode != null)
  273. return false;
  274. XmlDocumentNavigator o = other as XmlDocumentNavigator;
  275. if (o == null)
  276. return false;
  277. XmlNode n =
  278. o.node.NodeType == XmlNodeType.Attribute ?
  279. ((XmlAttribute) o.node).OwnerElement :
  280. o.node.ParentNode;
  281. for (;n != null; n = n.ParentNode)
  282. if (n == node)
  283. return true;
  284. return false;
  285. }
  286. public override bool IsSamePosition (XPathNavigator other)
  287. {
  288. XmlDocumentNavigator otherDocumentNavigator = other as XmlDocumentNavigator;
  289. if (otherDocumentNavigator != null)
  290. return node == otherDocumentNavigator.node
  291. && NsNode == otherDocumentNavigator.NsNode;
  292. return false;
  293. }
  294. public override bool MoveTo (XPathNavigator other)
  295. {
  296. XmlDocumentNavigator otherDocumentNavigator = other as XmlDocumentNavigator;
  297. if (otherDocumentNavigator != null) {
  298. if (document == otherDocumentNavigator.document) {
  299. node = otherDocumentNavigator.node;
  300. NsNode = otherDocumentNavigator.NsNode;
  301. return true;
  302. }
  303. }
  304. return false;
  305. }
  306. public override bool MoveToAttribute (string localName, string namespaceURI)
  307. {
  308. if (node.Attributes != null) {
  309. for (int i = 0; i < node.Attributes.Count; i++) {
  310. XmlAttribute attr = node.Attributes [i];
  311. if (attr.LocalName == localName
  312. && attr.NamespaceURI == namespaceURI) {
  313. node = attr;
  314. NsNode = null;
  315. return true;
  316. }
  317. }
  318. }
  319. return false;
  320. }
  321. #if NET_2_0
  322. #else
  323. public override bool MoveToFirst ()
  324. {
  325. return MoveToFirstImpl ();
  326. }
  327. #endif
  328. public override bool MoveToFirstAttribute ()
  329. {
  330. if (node.Attributes == null)
  331. return false;
  332. if (NodeType == XPathNodeType.Element) {
  333. for (int i = 0; i < node.Attributes.Count; i++) {
  334. XmlAttribute attr = node.Attributes [i];
  335. if (attr.NamespaceURI != Xmlns) {
  336. node = attr;
  337. NsNode = null;
  338. return true;
  339. }
  340. }
  341. }
  342. return false;
  343. }
  344. public override bool MoveToFirstChild ()
  345. {
  346. if (HasChildren) {
  347. XmlNode n = GetFirstChild (node);
  348. if (n == null)
  349. return false;
  350. node = n;
  351. return true;
  352. }
  353. return false;
  354. }
  355. public override bool MoveToFirstNamespace (XPathNamespaceScope namespaceScope)
  356. {
  357. if (NodeType != XPathNodeType.Element)
  358. return false;
  359. XmlElement el = node as XmlElement;
  360. if (node.Attributes != null) {
  361. do {
  362. for (int i = 0; i < el.Attributes.Count; i++) {
  363. XmlAttribute attr = el.Attributes [i];
  364. if (attr.NamespaceURI == Xmlns) {
  365. if (CheckNsNameAppearance (attr.Name, attr.Value))
  366. continue;
  367. NsNode = attr;
  368. return true;
  369. }
  370. }
  371. if (namespaceScope == XPathNamespaceScope.Local)
  372. return false;
  373. el = GetParentNode (el) as XmlElement;
  374. } while (el != null);
  375. }
  376. if (namespaceScope == XPathNamespaceScope.All) {
  377. if (CheckNsNameAppearance (nsNodeXml.Name, nsNodeXml.Value))
  378. return false;
  379. NsNode = nsNodeXml;
  380. return true;
  381. }
  382. else
  383. return false;
  384. }
  385. public override bool MoveToId (string id)
  386. {
  387. XmlElement eltNew = document.GetElementById (id);
  388. if (eltNew == null)
  389. return false;
  390. node = eltNew;
  391. return true;
  392. }
  393. public override bool MoveToNamespace (string name)
  394. {
  395. if (name == "xml") {
  396. NsNode = nsNodeXml;
  397. return true;
  398. }
  399. if (NodeType != XPathNodeType.Element)
  400. return false;
  401. XmlElement el = node as XmlElement;
  402. if (node.Attributes != null) {
  403. do {
  404. for (int i = 0; i < el.Attributes.Count; i++) {
  405. XmlAttribute attr = el.Attributes [i];
  406. if (attr.NamespaceURI == Xmlns && attr.Name == name) {
  407. NsNode = attr;
  408. return true;
  409. }
  410. }
  411. el = GetParentNode (node) as XmlElement;
  412. } while (el != null);
  413. }
  414. return false;
  415. }
  416. public override bool MoveToNext ()
  417. {
  418. if (NsNode != null)
  419. return false;
  420. XmlNode n = node;
  421. if (NodeType == XPathNodeType.Text) {
  422. do {
  423. n = GetNextSibling (n);
  424. if (n == null)
  425. return false;
  426. switch (n.NodeType) {
  427. case XmlNodeType.CDATA:
  428. case XmlNodeType.SignificantWhitespace:
  429. case XmlNodeType.Text:
  430. case XmlNodeType.Whitespace:
  431. continue;
  432. default:
  433. break;
  434. }
  435. break;
  436. } while (true);
  437. }
  438. else
  439. n = GetNextSibling (n);
  440. if (n == null)
  441. return false;
  442. node = n;
  443. return true;
  444. }
  445. public override bool MoveToNextAttribute ()
  446. {
  447. if (node == null)
  448. return false;
  449. if (NodeType != XPathNodeType.Attribute)
  450. return false;
  451. // Find current attribute.
  452. int pos = 0;
  453. XmlElement owner = ((XmlAttribute) node).OwnerElement;
  454. if (owner == null)
  455. return false;
  456. int count = owner.Attributes.Count;
  457. for(; pos < count; pos++)
  458. if (owner.Attributes [pos] == node)
  459. break;
  460. if (pos == count)
  461. return false; // Where is current attribute? Maybe removed.
  462. // Find next attribute.
  463. for(pos++; pos < count; pos++) {
  464. if (owner.Attributes [pos].NamespaceURI != Xmlns) {
  465. node = owner.Attributes [pos];
  466. NsNode = null;
  467. return true;
  468. }
  469. }
  470. return false;
  471. }
  472. public override bool MoveToNextNamespace (XPathNamespaceScope namespaceScope)
  473. {
  474. if (NsNode == nsNodeXml)
  475. // Current namespace is "xml", so there should be no more namespace nodes.
  476. return false;
  477. if (NsNode == null)
  478. return false;
  479. // Get current attribute's position.
  480. int pos = 0;
  481. XmlElement owner = ((XmlAttribute) NsNode).OwnerElement;
  482. if (owner == null)
  483. return false;
  484. int count = owner.Attributes.Count;
  485. for(; pos < count; pos++)
  486. if (owner.Attributes [pos] == NsNode)
  487. break;
  488. if (pos == count)
  489. return false; // Where is current attribute? Maybe removed.
  490. // Find next namespace from the same element as current ns node.
  491. for(pos++; pos < count; pos++) {
  492. if (owner.Attributes [pos].NamespaceURI == Xmlns) {
  493. XmlAttribute a = owner.Attributes [pos];
  494. if (CheckNsNameAppearance (a.Name, a.Value))
  495. continue;
  496. NsNode = a;
  497. return true;
  498. }
  499. }
  500. // If not found more, then find from ancestors.
  501. // But if scope is Local, then it returns false here.
  502. if (namespaceScope == XPathNamespaceScope.Local)
  503. return false;
  504. owner = GetParentNode (owner) as XmlElement;
  505. while (owner != null) {
  506. for (int i = 0; i < owner.Attributes.Count; i++) {
  507. XmlAttribute attr = owner.Attributes [i];
  508. if (attr.NamespaceURI == Xmlns) {
  509. if (CheckNsNameAppearance (attr.Name, attr.Value))
  510. continue;
  511. NsNode = attr;
  512. return true;
  513. }
  514. }
  515. owner = GetParentNode (owner) as XmlElement;
  516. }
  517. if (namespaceScope == XPathNamespaceScope.All) {
  518. if (CheckNsNameAppearance (nsNodeXml.Name, nsNodeXml.Value))
  519. return false;
  520. NsNode = nsNodeXml;
  521. return true;
  522. }
  523. return false;
  524. }
  525. public override bool MoveToParent ()
  526. {
  527. if (NsNode != null) {
  528. NsNode = null;
  529. return true;
  530. }
  531. else if (node.NodeType == XmlNodeType.Attribute) {
  532. XmlElement ownerElement = ((XmlAttribute)node).OwnerElement;
  533. if (ownerElement != null) {
  534. node = ownerElement;
  535. NsNode = null;
  536. return true;
  537. }
  538. else
  539. return false;
  540. }
  541. XmlNode n = GetParentNode (node);
  542. if (n == null)
  543. return false;
  544. node = n;
  545. NsNode = null;
  546. return true;
  547. }
  548. public override bool MoveToPrevious ()
  549. {
  550. if (NsNode != null)
  551. return false;
  552. XmlNode p = GetPreviousSibling (node);
  553. if (p == null)
  554. return false;
  555. node = p;
  556. return true;
  557. }
  558. public override void MoveToRoot ()
  559. {
  560. XmlAttribute attr = node as XmlAttribute;
  561. XmlNode tmp = attr != null ? attr.OwnerElement : node;
  562. for (XmlNode tmp2 = GetParentNode (tmp); tmp2 != null; tmp2 = GetParentNode (tmp2))
  563. tmp = tmp2;
  564. node = tmp;
  565. NsNode = null;
  566. }
  567. private XmlNode Node { get { return NsNode != null ? NsNode : node; } }
  568. XmlNode IHasXmlNode.GetNode ()
  569. {
  570. return Node;
  571. }
  572. private XmlNode GetFirstChild (XmlNode n)
  573. {
  574. if (n.FirstChild == null)
  575. return null;
  576. switch (n.FirstChild.NodeType) {
  577. case XmlNodeType.XmlDeclaration:
  578. case XmlNodeType.DocumentType:
  579. return GetNextSibling (n.FirstChild);
  580. case XmlNodeType.EntityReference:
  581. foreach (XmlNode c in n.ChildNodes) {
  582. if (c.NodeType == XmlNodeType.EntityReference) {
  583. XmlNode ec = GetFirstChild (c);
  584. if (ec != null)
  585. return ec;
  586. }
  587. return c;
  588. }
  589. return null;
  590. default:
  591. return n.FirstChild;
  592. }
  593. }
  594. private XmlNode GetLastChild (XmlNode n)
  595. {
  596. if (n.LastChild == null)
  597. return null;
  598. switch (n.LastChild.NodeType) {
  599. case XmlNodeType.XmlDeclaration:
  600. case XmlNodeType.DocumentType:
  601. return GetPreviousSibling (n.LastChild);
  602. case XmlNodeType.EntityReference:
  603. for (XmlNode c = n.LastChild; c != null; c = c.PreviousSibling) {
  604. if (c.NodeType == XmlNodeType.EntityReference) {
  605. XmlNode ec = GetLastChild (c);
  606. if (ec != null)
  607. return ec;
  608. }
  609. return c;
  610. }
  611. return null;
  612. default:
  613. return n.LastChild;
  614. }
  615. }
  616. private XmlNode GetPreviousSibling (XmlNode n)
  617. {
  618. if (n.PreviousSibling != null) {
  619. switch (n.PreviousSibling.NodeType) {
  620. case XmlNodeType.EntityReference:
  621. XmlNode c = GetLastChild (n.PreviousSibling);
  622. if (c != null)
  623. return c;
  624. else // empty entity reference etc.
  625. return GetPreviousSibling (n.PreviousSibling);
  626. case XmlNodeType.XmlDeclaration:
  627. case XmlNodeType.DocumentType:
  628. return GetPreviousSibling (n.PreviousSibling);
  629. default:
  630. return n.PreviousSibling;
  631. }
  632. } else {
  633. if (n.ParentNode == null || n.ParentNode.NodeType != XmlNodeType.EntityReference)
  634. return null;
  635. return GetPreviousSibling (n.ParentNode);
  636. }
  637. }
  638. private XmlNode GetNextSibling (XmlNode n)
  639. {
  640. if (n.NextSibling != null) {
  641. switch (n.NextSibling.NodeType) {
  642. case XmlNodeType.EntityReference:
  643. XmlNode c = GetFirstChild (n.NextSibling);
  644. if (c != null)
  645. return c;
  646. else // empty entity reference etc.
  647. return GetNextSibling (n.NextSibling);
  648. case XmlNodeType.XmlDeclaration:
  649. case XmlNodeType.DocumentType:
  650. return GetNextSibling (n.NextSibling);
  651. default:
  652. return n.NextSibling;
  653. }
  654. } else {
  655. if (n.ParentNode == null || n.ParentNode.NodeType != XmlNodeType.EntityReference)
  656. return null;
  657. return GetNextSibling (n.ParentNode);
  658. }
  659. }
  660. private XmlNode GetParentNode (XmlNode n)
  661. {
  662. if (n.ParentNode == null)
  663. return null;
  664. for (XmlNode p = n.ParentNode; p != null; p = p.ParentNode)
  665. if (p.NodeType != XmlNodeType.EntityReference)
  666. return p;
  667. return null;
  668. }
  669. #endregion
  670. }
  671. }