XmlNode.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. //
  2. // System.Xml.XmlNode
  3. //
  4. // Author:
  5. // Kral Ferch <[email protected]>
  6. //
  7. // (C) 2002 Kral Ferch
  8. //
  9. using System;
  10. using System.Collections;
  11. using System.Xml.XPath;
  12. namespace System.Xml
  13. {
  14. public abstract class XmlNode : ICloneable, IEnumerable, IXPathNavigable
  15. {
  16. #region Fields
  17. XmlDocument ownerDocument;
  18. XmlNode parentNode;
  19. #endregion
  20. #region Constructors
  21. protected internal XmlNode(XmlDocument ownerDocument)
  22. {
  23. this.ownerDocument = ownerDocument;
  24. }
  25. #endregion
  26. #region Properties
  27. public virtual XmlAttributeCollection Attributes
  28. {
  29. get { return null; }
  30. }
  31. [MonoTODO]
  32. public virtual string BaseURI
  33. {
  34. get { throw new NotImplementedException (); }
  35. }
  36. public virtual XmlNodeList ChildNodes {
  37. get {
  38. return new XmlNodeListChildren(this);
  39. }
  40. }
  41. public virtual XmlNode FirstChild {
  42. get {
  43. if (LastChild != null) {
  44. return LastLinkedChild.NextLinkedSibling;
  45. }
  46. else {
  47. return null;
  48. }
  49. }
  50. }
  51. public virtual bool HasChildNodes {
  52. get { return LastChild != null; }
  53. }
  54. [MonoTODO]
  55. public virtual string InnerText {
  56. get { throw new NotImplementedException (); }
  57. set { throw new NotImplementedException (); }
  58. }
  59. [MonoTODO]
  60. public virtual string InnerXml {
  61. get { throw new NotImplementedException (); }
  62. set { throw new NotImplementedException (); }
  63. }
  64. public virtual bool IsReadOnly {
  65. get { return false; }
  66. }
  67. [System.Runtime.CompilerServices.IndexerName("Item")]
  68. public virtual XmlElement this [string name] {
  69. get {
  70. foreach (XmlNode node in ChildNodes) {
  71. if ((node.NodeType == XmlNodeType.Element) &&
  72. (node.Name == name)) {
  73. return (XmlElement) node;
  74. }
  75. }
  76. return null;
  77. }
  78. }
  79. [System.Runtime.CompilerServices.IndexerName("Item")]
  80. public virtual XmlElement this [string localname, string ns] {
  81. get {
  82. foreach (XmlNode node in ChildNodes) {
  83. if ((node.NodeType == XmlNodeType.Element) &&
  84. (node.LocalName == localname) &&
  85. (node.NamespaceURI == ns)) {
  86. return (XmlElement) node;
  87. }
  88. }
  89. return null;
  90. }
  91. }
  92. public virtual XmlNode LastChild {
  93. get { return LastLinkedChild; }
  94. }
  95. internal virtual XmlLinkedNode LastLinkedChild {
  96. get { return null; }
  97. set { }
  98. }
  99. public abstract string LocalName { get; }
  100. public abstract string Name { get; }
  101. [MonoTODO]
  102. public virtual string NamespaceURI {
  103. get { throw new NotImplementedException (); }
  104. }
  105. public virtual XmlNode NextSibling {
  106. get { return null; }
  107. }
  108. public abstract XmlNodeType NodeType { get; }
  109. [MonoTODO]
  110. public virtual string OuterXml {
  111. get { throw new NotImplementedException (); }
  112. }
  113. public virtual XmlDocument OwnerDocument {
  114. get { return ownerDocument; }
  115. }
  116. public virtual XmlNode ParentNode {
  117. get { return parentNode; }
  118. }
  119. [MonoTODO]
  120. public virtual string Prefix {
  121. get { throw new NotImplementedException (); }
  122. set { throw new NotImplementedException (); }
  123. }
  124. public virtual XmlNode PreviousSibling {
  125. get { return null; }
  126. }
  127. [MonoTODO]
  128. public virtual string Value {
  129. get { throw new NotImplementedException (); }
  130. set { throw new NotImplementedException (); }
  131. }
  132. #endregion
  133. #region Methods
  134. public virtual XmlNode AppendChild (XmlNode newChild)
  135. {
  136. if (NodeType == XmlNodeType.Document || NodeType == XmlNodeType.Element || NodeType == XmlNodeType.Attribute) {
  137. XmlLinkedNode newLinkedChild = (XmlLinkedNode)newChild;
  138. XmlLinkedNode lastLinkedChild = LastLinkedChild;
  139. if (lastLinkedChild != null) {
  140. newLinkedChild.NextLinkedSibling = lastLinkedChild.NextLinkedSibling;
  141. lastLinkedChild.NextLinkedSibling = newLinkedChild;
  142. } else
  143. newLinkedChild.NextLinkedSibling = newLinkedChild;
  144. LastLinkedChild = newLinkedChild;
  145. return newChild;
  146. } else
  147. throw new InvalidOperationException();
  148. }
  149. [MonoTODO]
  150. public virtual XmlNode Clone ()
  151. {
  152. throw new NotImplementedException ();
  153. }
  154. public abstract XmlNode CloneNode (bool deep);
  155. [MonoTODO]
  156. public XPathNavigator CreateNavigator ()
  157. {
  158. throw new NotImplementedException ();
  159. }
  160. public IEnumerator GetEnumerator ()
  161. {
  162. return new XmlNodeListChildren(this).GetEnumerator();
  163. }
  164. [MonoTODO]
  165. public virtual string GetNamespaceOfPrefix (string prefix)
  166. {
  167. throw new NotImplementedException ();
  168. }
  169. [MonoTODO]
  170. public virtual string GetPrefixOfNamespace (string namespaceURI)
  171. {
  172. throw new NotImplementedException ();
  173. }
  174. object ICloneable.Clone ()
  175. {
  176. return Clone ();
  177. }
  178. IEnumerator IEnumerable.GetEnumerator ()
  179. {
  180. return GetEnumerator ();
  181. }
  182. [MonoTODO]
  183. public virtual XmlNode InsertAfter (XmlNode newChild, XmlNode refChild)
  184. {
  185. throw new NotImplementedException ();
  186. }
  187. [MonoTODO]
  188. public virtual XmlNode InsertBefore (XmlNode newChild, XmlNode refChild)
  189. {
  190. throw new NotImplementedException ();
  191. }
  192. [MonoTODO]
  193. public virtual void Normalize ()
  194. {
  195. throw new NotImplementedException ();
  196. }
  197. [MonoTODO]
  198. public virtual XmlNode PrependChild (XmlNode newChild)
  199. {
  200. throw new NotImplementedException ();
  201. }
  202. public virtual void RemoveAll ()
  203. {
  204. LastLinkedChild = null;
  205. }
  206. public virtual XmlNode RemoveChild (XmlNode oldChild)
  207. {
  208. if (NodeType == XmlNodeType.Document || NodeType == XmlNodeType.Element || NodeType == XmlNodeType.Attribute)
  209. {
  210. if (IsReadOnly)
  211. throw new ArgumentException();
  212. if (Object.ReferenceEquals(LastLinkedChild, LastLinkedChild.NextLinkedSibling) && Object.ReferenceEquals(LastLinkedChild, oldChild))
  213. LastLinkedChild = null;
  214. else {
  215. XmlLinkedNode oldLinkedChild = (XmlLinkedNode)oldChild;
  216. XmlLinkedNode beforeLinkedChild = LastLinkedChild;
  217. while (!Object.ReferenceEquals(beforeLinkedChild.NextLinkedSibling, LastLinkedChild) && !Object.ReferenceEquals(beforeLinkedChild.NextLinkedSibling, oldLinkedChild))
  218. beforeLinkedChild = beforeLinkedChild.NextLinkedSibling;
  219. if (!Object.ReferenceEquals(beforeLinkedChild.NextLinkedSibling, oldLinkedChild))
  220. throw new ArgumentException();
  221. beforeLinkedChild.NextLinkedSibling = oldLinkedChild.NextLinkedSibling;
  222. oldLinkedChild.NextLinkedSibling = null;
  223. }
  224. return oldChild;
  225. }
  226. else
  227. throw new ArgumentException();
  228. }
  229. [MonoTODO]
  230. public virtual XmlNode ReplaceChild (XmlNode newChild, XmlNode oldChild)
  231. {
  232. throw new NotImplementedException ();
  233. }
  234. [MonoTODO]
  235. public virtual XmlNodeList SelectNodes (string xpath)
  236. {
  237. throw new NotImplementedException ();
  238. }
  239. [MonoTODO]
  240. public virtual XmlNodeList SelectNodes (string xpath, XmlNamespaceManager nsmgr)
  241. {
  242. throw new NotImplementedException ();
  243. }
  244. [MonoTODO]
  245. public virtual XmlNode SelectSingleNode (string xpath)
  246. {
  247. throw new NotImplementedException ();
  248. }
  249. [MonoTODO]
  250. public virtual XmlNode SelectSingleNode (string xpath, XmlNamespaceManager nsmgr)
  251. {
  252. throw new NotImplementedException ();
  253. }
  254. internal void SetParentNode (XmlNode parent)
  255. {
  256. parentNode = parent;
  257. }
  258. [MonoTODO]
  259. public virtual bool Supports (string feature, string version)
  260. {
  261. throw new NotImplementedException ();
  262. }
  263. public abstract void WriteContentTo (XmlWriter w);
  264. public abstract void WriteTo (XmlWriter w);
  265. #endregion
  266. }
  267. }