XmlAttribute.cs 3.2 KB

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