2
0

XmlElement.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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. XmlNode attributeNode = Attributes.GetNamedItem (localName, namespaceURI);
  126. return attributeNode != null ? attributeNode.Value : String.Empty;
  127. }
  128. [MonoTODO]
  129. public virtual XmlAttribute GetAttributeNode (string name)
  130. {
  131. XmlNode attributeNode = Attributes.GetNamedItem (name);
  132. return attributeNode != null ? attributeNode as XmlAttribute : null;
  133. }
  134. [MonoTODO]
  135. public virtual XmlAttribute GetAttributeNode (string localName, string namespaceURI)
  136. {
  137. XmlNode attributeNode = Attributes.GetNamedItem (localName, namespaceURI);
  138. return attributeNode != null ? attributeNode as XmlAttribute : null;
  139. }
  140. [MonoTODO]
  141. public virtual XmlNodeList GetElementsByTagName (string name)
  142. {
  143. throw new NotImplementedException ();
  144. }
  145. [MonoTODO]
  146. public virtual XmlNodeList GetElementsByTagName (string localName, string namespaceURI)
  147. {
  148. throw new NotImplementedException ();
  149. }
  150. [MonoTODO]
  151. public virtual bool HasAttribute (string name)
  152. {
  153. XmlNode attributeNode = Attributes.GetNamedItem (name);
  154. return attributeNode != null;
  155. }
  156. [MonoTODO]
  157. public virtual bool HasAttribute (string localName, string namespaceURI)
  158. {
  159. throw new NotImplementedException ();
  160. }
  161. [MonoTODO ("Don't remove default attributes.")]
  162. public override void RemoveAll ()
  163. {
  164. // Remove the child nodes.
  165. base.RemoveAll ();
  166. // Remove all attributes.
  167. attributes.RemoveAll ();
  168. }
  169. [MonoTODO]
  170. public virtual void RemoveAllAttributes ()
  171. {
  172. throw new NotImplementedException ();
  173. }
  174. [MonoTODO]
  175. public virtual void RemoveAttribute (string name)
  176. {
  177. throw new NotImplementedException ();
  178. }
  179. [MonoTODO]
  180. public virtual void RemoveAttribute (string localName, string namespaceURI)
  181. {
  182. throw new NotImplementedException ();
  183. }
  184. [MonoTODO]
  185. public virtual XmlNode RemoveAttributeAt (int i)
  186. {
  187. throw new NotImplementedException ();
  188. }
  189. [MonoTODO]
  190. public virtual XmlAttribute RemoveAttributeNode (XmlAttribute oldAttr)
  191. {
  192. throw new NotImplementedException ();
  193. }
  194. [MonoTODO]
  195. public virtual XmlAttribute RemoveAttributeNode (string localName, string namespaceURI)
  196. {
  197. throw new NotImplementedException ();
  198. }
  199. [MonoTODO]
  200. public virtual void SetAttribute (string name, string value)
  201. {
  202. XmlAttribute attribute = OwnerDocument.CreateAttribute (name);
  203. attribute.SetOwnerElement (this);
  204. attribute.Value = value;
  205. Attributes.SetNamedItem (attribute);
  206. }
  207. [MonoTODO]
  208. public virtual string SetAttribute (string localName, string namespaceURI, string value)
  209. {
  210. throw new NotImplementedException ();
  211. }
  212. [MonoTODO]
  213. public virtual XmlAttribute SetAttributeNode (XmlAttribute newAttr)
  214. {
  215. XmlNode oldAttr = Attributes.SetNamedItem(newAttr);
  216. return oldAttr != null ? oldAttr as XmlAttribute : null;
  217. }
  218. [MonoTODO]
  219. public virtual XmlAttribute SetAttributeNode (string localName, string namespaceURI)
  220. {
  221. throw new NotImplementedException ();
  222. }
  223. public override void WriteContentTo (XmlWriter w)
  224. {
  225. foreach(XmlNode childNode in ChildNodes)
  226. childNode.WriteTo(w);
  227. }
  228. public override void WriteTo (XmlWriter w)
  229. {
  230. w.WriteStartElement(LocalName);
  231. foreach(XmlNode attributeNode in Attributes)
  232. attributeNode.WriteTo(w);
  233. WriteContentTo(w);
  234. w.WriteEndElement();
  235. }
  236. #endregion
  237. }
  238. }