XmlElement.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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 ("Setter.")]
  47. public override string InnerXml {
  48. get {
  49. // Not sure why this is an override. Passing through for now.
  50. return base.InnerXml;
  51. }
  52. set { throw new NotImplementedException (); }
  53. }
  54. [MonoTODO]
  55. public bool IsEmpty {
  56. get { throw new NotImplementedException (); }
  57. set { throw new NotImplementedException (); }
  58. }
  59. internal override XmlLinkedNode LastLinkedChild {
  60. get { return lastLinkedChild; }
  61. set { lastLinkedChild = value; }
  62. }
  63. public override string LocalName {
  64. get { return localName; }
  65. }
  66. public override string Name {
  67. get {
  68. return prefix != String.Empty ? prefix + ":" + localName : localName;
  69. }
  70. }
  71. public override string NamespaceURI {
  72. get { return namespaceURI; }
  73. }
  74. [MonoTODO]
  75. public override XmlNode NextSibling {
  76. get {
  77. return base.NextSibling;
  78. }
  79. }
  80. public override XmlNodeType NodeType {
  81. get {
  82. return XmlNodeType.Element;
  83. }
  84. }
  85. [MonoTODO]
  86. public override XmlDocument OwnerDocument {
  87. get {
  88. return base.OwnerDocument;
  89. }
  90. }
  91. public override string Prefix {
  92. get {
  93. return prefix;
  94. }
  95. }
  96. #endregion
  97. #region Methods
  98. [MonoTODO]
  99. public override XmlNode CloneNode (bool deep)
  100. {
  101. XmlNode node = new XmlElement (prefix, localName, namespaceURI,
  102. OwnerDocument);
  103. for (int i = 0; i < node.Attributes.Count; i++)
  104. node.AppendChild (node.Attributes [i].CloneNode (false));
  105. if (deep) {
  106. while ((node != null) && (node.HasChildNodes)) {
  107. AppendChild (node.NextSibling.CloneNode (true));
  108. node = node.NextSibling;
  109. }
  110. } // shallow cloning
  111. //
  112. // Reminder: Also look into Default attributes.
  113. //
  114. return node;
  115. }
  116. [MonoTODO]
  117. public virtual string GetAttribute (string name)
  118. {
  119. XmlNode attributeNode = Attributes.GetNamedItem (name);
  120. return attributeNode != null ? attributeNode.Value : String.Empty;
  121. }
  122. [MonoTODO]
  123. public virtual string GetAttribute (string localName, string namespaceURI)
  124. {
  125. throw new NotImplementedException ();
  126. }
  127. [MonoTODO]
  128. public virtual XmlAttribute GetAttributeNode (string name)
  129. {
  130. throw new NotImplementedException ();
  131. }
  132. [MonoTODO]
  133. public virtual XmlAttribute GetAttributeNode (string localName, string namespaceURI)
  134. {
  135. throw new NotImplementedException ();
  136. }
  137. [MonoTODO]
  138. public virtual XmlNodeList GetElementsByTagName (string name)
  139. {
  140. throw new NotImplementedException ();
  141. }
  142. [MonoTODO]
  143. public virtual XmlNodeList GetElementsByTagName (string localName, string namespaceURI)
  144. {
  145. throw new NotImplementedException ();
  146. }
  147. [MonoTODO]
  148. public virtual bool HasAttribute (string name)
  149. {
  150. XmlNode attributeNode = Attributes.GetNamedItem (name);
  151. return attributeNode != null;
  152. }
  153. [MonoTODO]
  154. public virtual bool HasAttribute (string localName, string namespaceURI)
  155. {
  156. throw new NotImplementedException ();
  157. }
  158. [MonoTODO ("Don't remove default attributes.")]
  159. public override void RemoveAll ()
  160. {
  161. // Remove the child nodes.
  162. base.RemoveAll ();
  163. // Remove all attributes.
  164. attributes.RemoveAll ();
  165. }
  166. [MonoTODO]
  167. public virtual void RemoveAllAttributes ()
  168. {
  169. throw new NotImplementedException ();
  170. }
  171. [MonoTODO]
  172. public virtual void RemoveAttribute (string name)
  173. {
  174. throw new NotImplementedException ();
  175. }
  176. [MonoTODO]
  177. public virtual void RemoveAttribute (string localName, string namespaceURI)
  178. {
  179. throw new NotImplementedException ();
  180. }
  181. [MonoTODO]
  182. public virtual XmlNode RemoveAttributeAt (int i)
  183. {
  184. throw new NotImplementedException ();
  185. }
  186. [MonoTODO]
  187. public virtual XmlAttribute RemoveAttributeNode (XmlAttribute oldAttr)
  188. {
  189. throw new NotImplementedException ();
  190. }
  191. [MonoTODO]
  192. public virtual XmlAttribute RemoveAttributeNode (string localName, string namespaceURI)
  193. {
  194. throw new NotImplementedException ();
  195. }
  196. [MonoTODO]
  197. public virtual void SetAttribute (string name, string value)
  198. {
  199. XmlAttribute attribute = OwnerDocument.CreateAttribute (name);
  200. attribute.SetOwnerElement (this);
  201. attribute.Value = value;
  202. Attributes.SetNamedItem (attribute);
  203. }
  204. [MonoTODO]
  205. public virtual string SetAttribute (string localName, string namespaceURI, string value)
  206. {
  207. throw new NotImplementedException ();
  208. }
  209. [MonoTODO]
  210. public virtual XmlAttribute SetAttributeNode (XmlAttribute newAttr)
  211. {
  212. throw new NotImplementedException ();
  213. }
  214. [MonoTODO]
  215. public virtual XmlAttribute SetAttributeNode (string localName, string namespaceURI)
  216. {
  217. throw new NotImplementedException ();
  218. }
  219. public override void WriteContentTo (XmlWriter w)
  220. {
  221. foreach(XmlNode childNode in ChildNodes)
  222. childNode.WriteTo(w);
  223. }
  224. public override void WriteTo (XmlWriter w)
  225. {
  226. w.WriteStartElement(LocalName);
  227. foreach(XmlNode attributeNode in Attributes)
  228. attributeNode.WriteTo(w);
  229. WriteContentTo(w);
  230. w.WriteEndElement();
  231. }
  232. #endregion
  233. }
  234. }