XmlElement.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. //
  2. // System.Xml.XmlAttribute
  3. //
  4. // Author:
  5. // Jason Diamond ([email protected])
  6. //
  7. // (C) 2002 Jason Diamond http://injektilo.org/
  8. //
  9. using System;
  10. namespace System.Xml
  11. {
  12. public class XmlElement : XmlLinkedNode
  13. {
  14. #region Fields
  15. private XmlAttributeCollection attributes;
  16. private XmlLinkedNode lastLinkedChild;
  17. private string localName;
  18. private string namespaceURI;
  19. private string prefix;
  20. #endregion
  21. #region Constructor
  22. protected internal XmlElement (
  23. string prefix,
  24. string localName,
  25. string namespaceURI,
  26. XmlDocument doc) : base (doc)
  27. {
  28. this.prefix = prefix;
  29. this.localName = localName;
  30. this.namespaceURI = namespaceURI;
  31. attributes = new XmlAttributeCollection (this);
  32. }
  33. #endregion
  34. #region Properties
  35. public override XmlAttributeCollection Attributes {
  36. get { return attributes; }
  37. }
  38. public virtual bool HasAttributes {
  39. get { return attributes.Count > 0; }
  40. }
  41. [MonoTODO]
  42. public override string InnerText {
  43. get { throw new NotImplementedException (); }
  44. set { throw new NotImplementedException (); }
  45. }
  46. [MonoTODO]
  47. public override string InnerXml {
  48. get { throw new NotImplementedException (); }
  49. set { throw new NotImplementedException (); }
  50. }
  51. [MonoTODO]
  52. public bool IsEmpty {
  53. get { throw new NotImplementedException (); }
  54. set { throw new NotImplementedException (); }
  55. }
  56. internal override XmlLinkedNode LastLinkedChild {
  57. get { return lastLinkedChild; }
  58. set { lastLinkedChild = value; }
  59. }
  60. public override string LocalName {
  61. get { return localName; }
  62. }
  63. public override string Name {
  64. get {
  65. return prefix != String.Empty ? prefix + ":" + localName : localName;
  66. }
  67. }
  68. public override string NamespaceURI {
  69. get { return namespaceURI; }
  70. }
  71. [MonoTODO]
  72. public override XmlNode NextSibling {
  73. get {
  74. return base.NextSibling;
  75. }
  76. }
  77. public override XmlNodeType NodeType {
  78. get {
  79. return XmlNodeType.Element;
  80. }
  81. }
  82. [MonoTODO]
  83. public override XmlDocument OwnerDocument {
  84. get {
  85. return base.OwnerDocument;
  86. }
  87. }
  88. public override string Prefix {
  89. get {
  90. return prefix;
  91. }
  92. }
  93. #endregion
  94. #region Methods
  95. [MonoTODO]
  96. public override XmlNode CloneNode (bool deep)
  97. {
  98. XmlNode node = new XmlElement (prefix, localName, namespaceURI,
  99. OwnerDocument);
  100. for (int i = 0; i < node.Attributes.Count; i++)
  101. node.AppendChild (node.Attributes [i].CloneNode (false));
  102. if (deep) {
  103. while ((node != null) && (node.HasChildNodes)) {
  104. AppendChild (node.NextSibling.CloneNode (true));
  105. node = node.NextSibling;
  106. }
  107. } // shallow cloning
  108. //
  109. // Reminder: Also look into Default attributes.
  110. //
  111. return node;
  112. }
  113. [MonoTODO]
  114. public virtual string GetAttribute (string name)
  115. {
  116. XmlNode attributeNode = Attributes.GetNamedItem (name);
  117. return attributeNode != null ? attributeNode.Value : String.Empty;
  118. }
  119. [MonoTODO]
  120. public virtual string GetAttribute (string localName, string namespaceURI)
  121. {
  122. throw new NotImplementedException ();
  123. }
  124. [MonoTODO]
  125. public virtual XmlAttribute GetAttributeNode (string name)
  126. {
  127. throw new NotImplementedException ();
  128. }
  129. [MonoTODO]
  130. public virtual XmlAttribute GetAttributeNode (string localName, string namespaceURI)
  131. {
  132. throw new NotImplementedException ();
  133. }
  134. [MonoTODO]
  135. public virtual XmlNodeList GetElementsByTagName (string name)
  136. {
  137. throw new NotImplementedException ();
  138. }
  139. [MonoTODO]
  140. public virtual XmlNodeList GetElementsByTagName (string localName, string namespaceURI)
  141. {
  142. throw new NotImplementedException ();
  143. }
  144. [MonoTODO]
  145. public virtual bool HasAttribute (string name)
  146. {
  147. XmlNode attributeNode = Attributes.GetNamedItem (name);
  148. return attributeNode != null;
  149. }
  150. [MonoTODO]
  151. public virtual bool HasAttribute (string localName, string namespaceURI)
  152. {
  153. throw new NotImplementedException ();
  154. }
  155. [MonoTODO ("Don't remove default attributes.")]
  156. public override void RemoveAll ()
  157. {
  158. // Remove the child nodes.
  159. base.RemoveAll ();
  160. // Remove all attributes.
  161. attributes.RemoveAll ();
  162. }
  163. [MonoTODO]
  164. public virtual void RemoveAllAttributes ()
  165. {
  166. throw new NotImplementedException ();
  167. }
  168. [MonoTODO]
  169. public virtual void RemoveAttribute (string name)
  170. {
  171. throw new NotImplementedException ();
  172. }
  173. [MonoTODO]
  174. public virtual void RemoveAttribute (string localName, string namespaceURI)
  175. {
  176. throw new NotImplementedException ();
  177. }
  178. [MonoTODO]
  179. public virtual XmlNode RemoveAttributeAt (int i)
  180. {
  181. throw new NotImplementedException ();
  182. }
  183. [MonoTODO]
  184. public virtual XmlAttribute RemoveAttributeNode (XmlAttribute oldAttr)
  185. {
  186. throw new NotImplementedException ();
  187. }
  188. [MonoTODO]
  189. public virtual XmlAttribute RemoveAttributeNode (string localName, string namespaceURI)
  190. {
  191. throw new NotImplementedException ();
  192. }
  193. [MonoTODO]
  194. public virtual void SetAttribute (string name, string value)
  195. {
  196. XmlAttribute attribute = OwnerDocument.CreateAttribute (name);
  197. attribute.SetOwnerElement (this);
  198. attribute.Value = value;
  199. Attributes.SetNamedItem (attribute);
  200. }
  201. [MonoTODO]
  202. public virtual void SetAttribute (string localName, string namespaceURI, string value)
  203. {
  204. throw new NotImplementedException ();
  205. }
  206. [MonoTODO]
  207. public virtual XmlAttribute SetAttributeNode (XmlAttribute newAttr)
  208. {
  209. throw new NotImplementedException ();
  210. }
  211. [MonoTODO]
  212. public virtual XmlAttribute SetAttributeNode (string localName, string namespaceURI)
  213. {
  214. throw new NotImplementedException ();
  215. }
  216. public override void WriteContentTo (XmlWriter w)
  217. {
  218. foreach(XmlNode childNode in ChildNodes)
  219. childNode.WriteTo(w);
  220. }
  221. public override void WriteTo (XmlWriter w)
  222. {
  223. w.WriteStartElement(LocalName);
  224. foreach(XmlNode attributeNode in Attributes)
  225. attributeNode.WriteTo(w);
  226. WriteContentTo(w);
  227. w.WriteEndElement();
  228. }
  229. #endregion
  230. }
  231. }