XmlNode.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. //
  2. // System.Xml.XmlNode
  3. //
  4. // Author:
  5. // Kral Ferch <[email protected]>
  6. // Atsushi Enomoto <[email protected]>
  7. //
  8. // (C) 2002 Kral Ferch
  9. // (C) 2002 Atsushi Enomoto
  10. //
  11. using System;
  12. using System.Collections;
  13. using System.IO;
  14. using System.Text;
  15. using System.Xml.XPath;
  16. namespace System.Xml
  17. {
  18. public abstract class XmlNode : ICloneable, IEnumerable, IXPathNavigable
  19. {
  20. #region Fields
  21. XmlDocument ownerDocument;
  22. XmlNode parentNode;
  23. StringBuilder tmpBuilder;
  24. #endregion
  25. #region Constructors
  26. internal XmlNode (XmlDocument ownerDocument)
  27. {
  28. this.ownerDocument = ownerDocument;
  29. }
  30. #endregion
  31. #region Properties
  32. public virtual XmlAttributeCollection Attributes {
  33. get { return null; }
  34. }
  35. public virtual string BaseURI {
  36. get {
  37. // Isn't it conformant to W3C XML Base Recommendation?
  38. // As far as I tested, there are not...
  39. return (ParentNode != null) ? ParentNode.BaseURI : OwnerDocument.BaseURI;
  40. }
  41. }
  42. public virtual XmlNodeList ChildNodes {
  43. get {
  44. return new XmlNodeListChildren (this);
  45. }
  46. }
  47. public virtual XmlNode FirstChild {
  48. get {
  49. if (LastChild != null) {
  50. return LastLinkedChild.NextLinkedSibling;
  51. }
  52. else {
  53. return null;
  54. }
  55. }
  56. }
  57. public virtual bool HasChildNodes {
  58. get { return LastChild != null; }
  59. }
  60. public virtual string InnerText {
  61. get {
  62. StringBuilder builder = new StringBuilder ();
  63. AppendChildValues (this, builder);
  64. return builder.ToString ();
  65. }
  66. set { throw new InvalidOperationException ("This node is read only. Cannot be modified."); }
  67. }
  68. private void AppendChildValues (XmlNode parent, StringBuilder builder)
  69. {
  70. XmlNode node = parent.FirstChild;
  71. while (node != null) {
  72. switch (node.NodeType) {
  73. case XmlNodeType.Text:
  74. case XmlNodeType.CDATA:
  75. case XmlNodeType.SignificantWhitespace:
  76. case XmlNodeType.Whitespace:
  77. builder.Append (node.Value);
  78. break;
  79. }
  80. AppendChildValues (node, builder);
  81. node = node.NextSibling;
  82. }
  83. }
  84. public virtual string InnerXml {
  85. get {
  86. StringWriter sw = new StringWriter ();
  87. XmlTextWriter xtw = new XmlTextWriter (sw);
  88. WriteContentTo (xtw);
  89. return sw.GetStringBuilder ().ToString ();
  90. }
  91. set {
  92. throw new InvalidOperationException ("This node is readonly or doesn't have any children.");
  93. }
  94. }
  95. public virtual bool IsReadOnly {
  96. get { return false; }
  97. }
  98. [System.Runtime.CompilerServices.IndexerName("Item")]
  99. public virtual XmlElement this [string name] {
  100. get {
  101. foreach (XmlNode node in ChildNodes) {
  102. if ((node.NodeType == XmlNodeType.Element) &&
  103. (node.Name == name)) {
  104. return (XmlElement) node;
  105. }
  106. }
  107. return null;
  108. }
  109. }
  110. [System.Runtime.CompilerServices.IndexerName("Item")]
  111. public virtual XmlElement this [string localname, string ns] {
  112. get {
  113. foreach (XmlNode node in ChildNodes) {
  114. if ((node.NodeType == XmlNodeType.Element) &&
  115. (node.LocalName == localname) &&
  116. (node.NamespaceURI == ns)) {
  117. return (XmlElement) node;
  118. }
  119. }
  120. return null;
  121. }
  122. }
  123. public virtual XmlNode LastChild {
  124. get { return LastLinkedChild; }
  125. }
  126. internal virtual XmlLinkedNode LastLinkedChild {
  127. get { return null; }
  128. set { }
  129. }
  130. public abstract string LocalName { get; }
  131. public abstract string Name { get; }
  132. public virtual string NamespaceURI {
  133. get { return String.Empty; }
  134. }
  135. public virtual XmlNode NextSibling {
  136. get { return null; }
  137. }
  138. public abstract XmlNodeType NodeType { get; }
  139. internal virtual XPathNodeType XPathNodeType {
  140. get {
  141. throw new InvalidOperationException ("Can not get XPath node type from " + this.GetType ().ToString ());
  142. }
  143. }
  144. public virtual string OuterXml {
  145. get {
  146. StringWriter sw = new StringWriter ();
  147. XmlTextWriter xtw = new XmlTextWriter (sw);
  148. WriteTo (xtw);
  149. return sw.ToString ();
  150. }
  151. }
  152. public virtual XmlDocument OwnerDocument {
  153. get { return ownerDocument; }
  154. }
  155. public virtual XmlNode ParentNode {
  156. get { return parentNode; }
  157. }
  158. public virtual string Prefix {
  159. get { return String.Empty; }
  160. set {}
  161. }
  162. public virtual XmlNode PreviousSibling {
  163. get { return null; }
  164. }
  165. public virtual string Value {
  166. get { return null; }
  167. set { throw new InvalidOperationException ("This node does not have a value"); }
  168. }
  169. internal virtual string XmlLang {
  170. get {
  171. if(Attributes != null)
  172. foreach(XmlAttribute attr in Attributes)
  173. if(attr.Name == "xml:lang")
  174. return attr.Value;
  175. return (ParentNode != null) ? ParentNode.XmlLang : OwnerDocument.XmlLang;
  176. }
  177. }
  178. internal virtual XmlSpace XmlSpace {
  179. get {
  180. if(Attributes != null) {
  181. foreach(XmlAttribute attr in Attributes) {
  182. if(attr.Name == "xml:space") {
  183. switch(attr.Value) {
  184. case "preserve": return XmlSpace.Preserve;
  185. case "default": return XmlSpace.Default;
  186. }
  187. break;
  188. }
  189. }
  190. }
  191. return (ParentNode != null) ? ParentNode.XmlSpace : OwnerDocument.XmlSpace;
  192. }
  193. }
  194. #endregion
  195. #region Methods
  196. public virtual XmlNode AppendChild (XmlNode newChild)
  197. {
  198. // I assume that AppendChild(n) equals to InsertAfter(n, this.LastChild) or InsertBefore(n, null)
  199. return InsertBefore (newChild, null);
  200. }
  201. public virtual XmlNode Clone ()
  202. {
  203. // By MS document, it is equivalent to CloneNode(true).
  204. return this.CloneNode (true);
  205. }
  206. public abstract XmlNode CloneNode (bool deep);
  207. public XPathNavigator CreateNavigator ()
  208. {
  209. XmlDocument document = this.NodeType == XmlNodeType.Document ?
  210. this as XmlDocument : this.ownerDocument;
  211. return document.CreateNavigator (this);
  212. }
  213. public IEnumerator GetEnumerator ()
  214. {
  215. return new XmlNodeListChildren (this).GetEnumerator ();
  216. }
  217. public virtual string GetNamespaceOfPrefix (string prefix)
  218. {
  219. XmlNode node;
  220. switch (NodeType) {
  221. case XmlNodeType.Attribute:
  222. node = ((XmlAttribute) this).OwnerElement;
  223. if (node == null)
  224. return String.Empty;
  225. break;
  226. case XmlNodeType.Element:
  227. node = this;
  228. break;
  229. default:
  230. node = ParentNode;
  231. break;
  232. }
  233. while (node != null) {
  234. if (node.Prefix == prefix)
  235. return node.NamespaceURI;
  236. foreach (XmlAttribute attr in node.Attributes) {
  237. if (prefix == attr.LocalName && attr.Prefix == "xmlns"
  238. || attr.Name == "xmlns" && prefix == String.Empty)
  239. return attr.Value;
  240. }
  241. node = node.ParentNode;
  242. }
  243. return String.Empty;
  244. }
  245. public virtual string GetPrefixOfNamespace (string namespaceURI)
  246. {
  247. XmlNode node;
  248. switch (NodeType) {
  249. case XmlNodeType.Attribute:
  250. node = ((XmlAttribute) this).OwnerElement;
  251. break;
  252. case XmlNodeType.Element:
  253. node = this;
  254. break;
  255. default:
  256. node = ParentNode;
  257. break;
  258. }
  259. while (node.NodeType != XmlNodeType.Document) {
  260. foreach (XmlAttribute attr in node.Attributes) {
  261. if (attr.Prefix == "xmlns" && attr.Value == namespaceURI)
  262. return attr.LocalName;
  263. else if (attr.Name == "xmlns" && attr.Value == namespaceURI)
  264. return String.Empty;
  265. }
  266. node = node.ParentNode;
  267. }
  268. return String.Empty;
  269. }
  270. object ICloneable.Clone ()
  271. {
  272. return Clone ();
  273. }
  274. IEnumerator IEnumerable.GetEnumerator ()
  275. {
  276. return GetEnumerator ();
  277. }
  278. public virtual XmlNode InsertAfter (XmlNode newChild, XmlNode refChild)
  279. {
  280. // I assume that insertAfter(n1, n2) equals to InsertBefore(n1, n2.PreviousSibling).
  281. // I took this way because current implementation
  282. // Calling InsertAfter() from InsertBefore() is
  283. // subsequently to use 'NextSibling' which is
  284. // faster than 'PreviousSibling' (these children are
  285. // forward-only linked list).
  286. XmlNode argNode = null;
  287. if(refChild != null)
  288. argNode = refChild.NextSibling;
  289. else if(ChildNodes.Count > 0)
  290. argNode = FirstChild;
  291. return InsertBefore (newChild, argNode);
  292. }
  293. public virtual XmlNode InsertBefore (XmlNode newChild, XmlNode refChild)
  294. {
  295. XmlDocument ownerDoc = (NodeType == XmlNodeType.Document) ? (XmlDocument)this : OwnerDocument;
  296. if (NodeType != XmlNodeType.Element &&
  297. NodeType != XmlNodeType.Attribute &&
  298. NodeType != XmlNodeType.Document &&
  299. NodeType != XmlNodeType.DocumentFragment)
  300. throw new InvalidOperationException (String.Format ("current node {0} is not allowed to have any children.", NodeType));
  301. switch (NodeType) {
  302. case XmlNodeType.Attribute:
  303. switch (newChild.NodeType) {
  304. case XmlNodeType.Text:
  305. case XmlNodeType.EntityReference:
  306. break;
  307. default:
  308. throw new ArgumentException (String.Format (
  309. "Cannot insert specified type of node {0} as a child of this node {0}.",
  310. newChild.NodeType, NodeType));
  311. }
  312. break;
  313. case XmlNodeType.Element:
  314. switch (newChild.NodeType) {
  315. case XmlNodeType.Attribute:
  316. case XmlNodeType.Document:
  317. case XmlNodeType.DocumentType:
  318. case XmlNodeType.Entity:
  319. case XmlNodeType.Notation:
  320. case XmlNodeType.XmlDeclaration:
  321. throw new ArgumentException ("Cannot insert specified type of node as a child of this node.");
  322. }
  323. break;
  324. }
  325. if (IsReadOnly)
  326. throw new ArgumentException ("The specified node is readonly.");
  327. if (newChild.OwnerDocument != ownerDoc)
  328. throw new ArgumentException ("Can't append a node created by another document.");
  329. if (refChild != null && newChild.OwnerDocument != refChild.OwnerDocument)
  330. throw new ArgumentException ("argument nodes are on the different documents.");
  331. // This check is done by MS.NET 1.0, but isn't done for MS.NET 1.1.
  332. // Skip this check in the meantime...
  333. // if(this == ownerDoc && ownerDoc.DocumentElement != null && (newChild is XmlElement))
  334. // throw new XmlException ("multiple document element not allowed.");
  335. // checking validity finished. then appending...
  336. return insertBeforeIntern (newChild, refChild);
  337. }
  338. internal XmlNode insertBeforeIntern (XmlNode newChild, XmlNode refChild)
  339. {
  340. XmlDocument ownerDoc = (NodeType == XmlNodeType.Document) ? (XmlDocument)this : OwnerDocument;
  341. ownerDoc.onNodeInserting (newChild, this);
  342. if(newChild.ParentNode != null)
  343. newChild.ParentNode.RemoveChild (newChild);
  344. if(newChild.NodeType == XmlNodeType.DocumentFragment) {
  345. int x = newChild.ChildNodes.Count;
  346. for(int i=0; i<x; i++) {
  347. XmlNode n = newChild.ChildNodes [0];
  348. this.InsertBefore (n, refChild); // recursively invokes events. (It is compatible with MS implementation.)
  349. }
  350. }
  351. else {
  352. XmlLinkedNode newLinkedChild = (XmlLinkedNode) newChild;
  353. XmlLinkedNode lastLinkedChild = LastLinkedChild;
  354. newLinkedChild.parentNode = this;
  355. if(refChild == null) {
  356. // append last, so:
  357. // * set nextSibling of previous lastchild to newChild
  358. // * set lastchild = newChild
  359. // * set next of newChild to firstChild
  360. if(LastLinkedChild != null) {
  361. XmlLinkedNode formerFirst = FirstChild as XmlLinkedNode;
  362. LastLinkedChild.NextLinkedSibling = newLinkedChild;
  363. LastLinkedChild = newLinkedChild;
  364. newLinkedChild.NextLinkedSibling = formerFirst;
  365. }
  366. else {
  367. LastLinkedChild = newLinkedChild;
  368. LastLinkedChild.NextLinkedSibling = newLinkedChild; // FirstChild
  369. }
  370. }
  371. else {
  372. // append not last, so:
  373. // * if newchild is first, then set next of lastchild is newChild.
  374. // otherwise, set next of previous sibling to newChild
  375. // * set next of newChild to refChild
  376. XmlLinkedNode prev = refChild.PreviousSibling as XmlLinkedNode;
  377. if(prev == null)
  378. LastLinkedChild.NextLinkedSibling = newLinkedChild;
  379. else
  380. prev.NextLinkedSibling = newLinkedChild;
  381. newLinkedChild.NextLinkedSibling = refChild as XmlLinkedNode;
  382. }
  383. ownerDoc.onNodeInserted (newChild, newChild.ParentNode);
  384. }
  385. return newChild;
  386. }
  387. public virtual void Normalize ()
  388. {
  389. // if (tmpBuilder == null)
  390. tmpBuilder = new StringBuilder ();
  391. // tmpBuilder.Length = 0;
  392. int count = this.ChildNodes.Count;
  393. int start = 0;
  394. for (int i = 0; i < count; i++) {
  395. XmlNode c = ChildNodes [i];
  396. switch (c.NodeType) {
  397. case XmlNodeType.Text:
  398. case XmlNodeType.Whitespace:
  399. case XmlNodeType.SignificantWhitespace:
  400. tmpBuilder.Append (c.Value);
  401. break;
  402. default:
  403. c.Normalize ();
  404. NormalizeRange (start, i);
  405. // Continue to normalize from next node.
  406. start = i + 1;
  407. break;
  408. }
  409. }
  410. if (start < count) {
  411. NormalizeRange (start, count);
  412. }
  413. tmpBuilder = null;
  414. }
  415. private void NormalizeRange (int start, int i)
  416. {
  417. int keepPos = -1;
  418. // If Texts and Whitespaces are mixed, Text takes precedence to remain.
  419. // i.e. Whitespace should be removed.
  420. for (int j = start; j < i; j++) {
  421. XmlNode keep = ChildNodes [j];
  422. if (keep.NodeType == XmlNodeType.Text) {
  423. keepPos = j;
  424. break;
  425. }
  426. else if (keep.NodeType == XmlNodeType.SignificantWhitespace)
  427. keepPos = j;
  428. // but don't break up to find Text nodes.
  429. }
  430. // But if no Texts and one or more Whitespaces, then the first
  431. if (keepPos < 0 && i > start)
  432. keepPos = 0;
  433. if (keepPos >= 0) {
  434. for (int del = start; del < keepPos; del++)
  435. RemoveChild (ChildNodes [del]);
  436. for (int del = keepPos + 1; del < i; del++)
  437. RemoveChild (ChildNodes [del]);
  438. }
  439. ChildNodes [keepPos].Value = tmpBuilder.ToString ();
  440. tmpBuilder.Length = 0;
  441. }
  442. public virtual XmlNode PrependChild (XmlNode newChild)
  443. {
  444. return InsertAfter (newChild, null);
  445. }
  446. public virtual void RemoveAll ()
  447. {
  448. if (Attributes != null)
  449. Attributes.RemoveAll ();
  450. XmlNode next = null;
  451. for (XmlNode node = FirstChild; node != null; node = next) {
  452. next = node.NextSibling;
  453. RemoveChild (node);
  454. }
  455. }
  456. public virtual XmlNode RemoveChild (XmlNode oldChild)
  457. {
  458. XmlDocument ownerDoc = (NodeType == XmlNodeType.Document) ? (XmlDocument)this : OwnerDocument;
  459. if(oldChild.ParentNode != this)
  460. throw new XmlException ("specified child is not child of this node.");
  461. ownerDoc.onNodeRemoving (oldChild, oldChild.ParentNode);
  462. if (NodeType != XmlNodeType.Attribute &&
  463. NodeType != XmlNodeType.Element &&
  464. NodeType != XmlNodeType.Document &&
  465. NodeType != XmlNodeType.DocumentFragment)
  466. throw new ArgumentException (String.Format ("This {0} node cannot remove child.", NodeType));
  467. if (IsReadOnly)
  468. throw new ArgumentException (String.Format ("This {0} node is read only.", NodeType));
  469. if (Object.ReferenceEquals (LastLinkedChild, LastLinkedChild.NextLinkedSibling) && Object.ReferenceEquals (LastLinkedChild, oldChild))
  470. // If there is only one children, simply clear.
  471. LastLinkedChild = null;
  472. else {
  473. XmlLinkedNode oldLinkedChild = (XmlLinkedNode) oldChild;
  474. XmlLinkedNode beforeLinkedChild = LastLinkedChild;
  475. XmlLinkedNode firstChild = (XmlLinkedNode) FirstChild;
  476. while (Object.ReferenceEquals (beforeLinkedChild.NextLinkedSibling, LastLinkedChild) == false &&
  477. Object.ReferenceEquals (beforeLinkedChild.NextLinkedSibling, oldLinkedChild) == false)
  478. beforeLinkedChild = beforeLinkedChild.NextLinkedSibling;
  479. if (Object.ReferenceEquals (beforeLinkedChild.NextLinkedSibling, oldLinkedChild) == false)
  480. throw new ArgumentException ();
  481. beforeLinkedChild.NextLinkedSibling = oldLinkedChild.NextLinkedSibling;
  482. // Each derived class may have its own LastLinkedChild, so we must set it explicitly.
  483. if (oldLinkedChild.NextLinkedSibling == firstChild)
  484. this.LastLinkedChild = beforeLinkedChild;
  485. oldLinkedChild.NextLinkedSibling = null;
  486. }
  487. ownerDoc.onNodeRemoved (oldChild, oldChild.ParentNode);
  488. oldChild.parentNode = null; // clear parent 'after' above logic.
  489. return oldChild;
  490. }
  491. public virtual XmlNode ReplaceChild (XmlNode newChild, XmlNode oldChild)
  492. {
  493. if(oldChild.ParentNode != this)
  494. throw new InvalidOperationException ("oldChild is not a child of this node.");
  495. XmlNode parent = this.ParentNode;
  496. while(parent != null) {
  497. if(newChild == parent)
  498. throw new InvalidOperationException ("newChild is ancestor of this node.");
  499. parent = parent.ParentNode;
  500. }
  501. foreach(XmlNode n in ChildNodes) {
  502. if(n == oldChild) {
  503. XmlNode prev = oldChild.PreviousSibling;
  504. RemoveChild (oldChild);
  505. InsertAfter (newChild, prev);
  506. break;
  507. }
  508. }
  509. return oldChild;
  510. }
  511. public XmlNodeList SelectNodes (string xpath)
  512. {
  513. return SelectNodes (xpath, null);
  514. }
  515. [MonoTODO ("return nodes in document order")]
  516. public XmlNodeList SelectNodes (string xpath, XmlNamespaceManager nsmgr)
  517. {
  518. XPathNavigator nav = CreateNavigator ();
  519. XPathExpression expr = nav.Compile (xpath);
  520. if (nsmgr != null)
  521. expr.SetContext (nsmgr);
  522. XPathNodeIterator iter = nav.Select (expr);
  523. ArrayList rgNodes = new ArrayList ();
  524. while (iter.MoveNext ())
  525. {
  526. rgNodes.Add (((XmlDocumentNavigator) iter.Current).Node);
  527. }
  528. return new XmlNodeArrayList (rgNodes);
  529. }
  530. public XmlNode SelectSingleNode (string xpath)
  531. {
  532. return SelectSingleNode (xpath, null);
  533. }
  534. [MonoTODO ("return node in document order")]
  535. public XmlNode SelectSingleNode (string xpath, XmlNamespaceManager nsmgr)
  536. {
  537. XPathNavigator nav = CreateNavigator ();
  538. XPathExpression expr = nav.Compile (xpath);
  539. if (nsmgr != null)
  540. expr.SetContext (nsmgr);
  541. XPathNodeIterator iter = nav.Select (expr);
  542. if (!iter.MoveNext ())
  543. return null;
  544. return ((XmlDocumentNavigator) iter.Current).Node;
  545. }
  546. public virtual bool Supports (string feature, string version)
  547. {
  548. if (String.Compare (feature, "xml", true) == 0 // not case-sensitive
  549. && (String.Compare (version, "1.0", true) == 0
  550. || String.Compare (version, "2.0", true) == 0))
  551. return true;
  552. else
  553. return false;
  554. }
  555. public abstract void WriteContentTo (XmlWriter w);
  556. public abstract void WriteTo (XmlWriter w);
  557. // It parses this and all the ancestor elements,
  558. // find 'xmlns' declarations, stores and then return them.
  559. // TODO: tests
  560. internal XmlNamespaceManager ConstructNamespaceManager ()
  561. {
  562. XmlDocument doc = this is XmlDocument ? (XmlDocument)this : this.OwnerDocument;
  563. XmlNamespaceManager nsmgr = new XmlNamespaceManager (doc.NameTable);
  564. XmlElement el = null;
  565. switch(this.NodeType) {
  566. case XmlNodeType.Attribute:
  567. el = ((XmlAttribute)this).OwnerElement;
  568. break;
  569. case XmlNodeType.Element:
  570. el = this as XmlElement;
  571. break;
  572. default:
  573. el = this.ParentNode as XmlElement;
  574. break;
  575. }
  576. while(el != null) {
  577. foreach(XmlAttribute attr in el.Attributes) {
  578. if(attr.Prefix == "xmlns") {
  579. if (nsmgr.LookupNamespace (attr.LocalName) != attr.Value)
  580. nsmgr.AddNamespace (attr.LocalName, attr.Value);
  581. } else if(attr.Name == "xmlns") {
  582. if(nsmgr.LookupNamespace (String.Empty) != attr.Value)
  583. nsmgr.AddNamespace (String.Empty, attr.Value);
  584. }
  585. }
  586. // When reached to document, then it will set null value :)
  587. el = el.ParentNode as XmlElement;
  588. }
  589. return nsmgr;
  590. }
  591. #endregion
  592. }
  593. }