XmlAttribute.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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 XmlAttribute : XmlNode
  13. {
  14. #region Fields
  15. private XmlElement ownerElement;
  16. private XmlLinkedNode lastChild;
  17. private string localName;
  18. private string namespaceURI;
  19. private string prefix;
  20. #endregion
  21. #region Constructor
  22. [MonoTODO("need to set namespaceURI if prefix is recognized built-in ones like xmlns")]
  23. protected internal XmlAttribute (
  24. string prefix,
  25. string localName,
  26. string namespaceURI,
  27. XmlDocument doc) : base (doc)
  28. {
  29. this.prefix = prefix;
  30. this.localName = localName;
  31. this.namespaceURI = namespaceURI;
  32. }
  33. #endregion
  34. #region Properties
  35. [MonoTODO]
  36. public override string BaseURI {
  37. get {
  38. throw new NotImplementedException ();
  39. }
  40. }
  41. [MonoTODO]
  42. public override string InnerText {
  43. get {
  44. throw new NotImplementedException ();
  45. }
  46. set {
  47. throw new NotImplementedException ();
  48. }
  49. }
  50. [MonoTODO ("Setter.")]
  51. public override string InnerXml {
  52. get {
  53. // Not sure why this is an override. Passing through for now.
  54. return base.InnerXml;
  55. }
  56. set {
  57. throw new NotImplementedException ();
  58. }
  59. }
  60. public override string LocalName {
  61. get {
  62. return localName;
  63. }
  64. }
  65. public override string Name {
  66. get {
  67. return prefix != String.Empty ? prefix + ":" + localName : localName;
  68. }
  69. }
  70. public override string NamespaceURI {
  71. get {
  72. return namespaceURI;
  73. }
  74. }
  75. public override XmlNodeType NodeType {
  76. get {
  77. return XmlNodeType.Attribute;
  78. }
  79. }
  80. public override XmlDocument OwnerDocument {
  81. get {
  82. return base.OwnerDocument;
  83. }
  84. }
  85. public virtual XmlElement OwnerElement {
  86. get {
  87. return ownerElement;
  88. }
  89. }
  90. [MonoTODO]
  91. public override XmlNode ParentNode {
  92. get {
  93. return null;
  94. }
  95. }
  96. [MonoTODO]
  97. // We gotta do more in the set block here
  98. // We need to do the proper tests and throw
  99. // the correct Exceptions
  100. public override string Prefix {
  101. set {
  102. prefix = value;
  103. }
  104. get {
  105. return prefix;
  106. }
  107. }
  108. [MonoTODO]
  109. public virtual bool Specified {
  110. get {
  111. throw new NotImplementedException ();
  112. }
  113. }
  114. public override string Value {
  115. get {
  116. XmlNode firstChild = FirstChild;
  117. if (firstChild == null)
  118. return String.Empty;
  119. return firstChild.Value;
  120. }
  121. set {
  122. XmlNode firstChild = FirstChild;
  123. if (firstChild == null)
  124. AppendChild (OwnerDocument.CreateTextNode (value));
  125. else
  126. firstChild.Value = value;
  127. }
  128. }
  129. #endregion
  130. #region Methods
  131. public override XmlNode CloneNode (bool deep)
  132. {
  133. XmlNode node = new XmlAttribute (prefix, localName, namespaceURI,
  134. OwnerDocument);
  135. if (deep) {
  136. while ((node != null) && (node.HasChildNodes)) {
  137. AppendChild (node.NextSibling.CloneNode (true));
  138. node = node.NextSibling;
  139. }
  140. }
  141. return node;
  142. }
  143. internal void SetOwnerElement (XmlElement ownerElement)
  144. {
  145. this.ownerElement = ownerElement;
  146. }
  147. public override void WriteContentTo (XmlWriter w)
  148. {
  149. w.WriteString (Value);
  150. }
  151. public override void WriteTo (XmlWriter w)
  152. {
  153. w.WriteAttributeString (prefix, localName, namespaceURI, Value);
  154. }
  155. #endregion
  156. internal override XmlLinkedNode LastLinkedChild {
  157. get { return lastChild; }
  158. set { lastChild = value; }
  159. }
  160. }
  161. }