XmlAttribute.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
  2. //
  3. // System.Xml.XmlAttribute
  4. //
  5. // Author:
  6. // Daniel Weber ([email protected])
  7. //
  8. // (C) 2001 Daniel Weber
  9. using System;
  10. namespace System.Xml
  11. {
  12. /// <summary>
  13. /// Summary description for XmlAttribute.
  14. /// </summary>
  15. public class XmlAttribute : XmlNode
  16. {
  17. // ============ private data structures ==============================
  18. private XmlNode FOwnerElement;
  19. string FattrName;
  20. string FattrValue;
  21. //==== Public Properties ====================================================
  22. /// <summary>
  23. /// Returns the local name of the attribute. For attributes, this is the same as Name
  24. /// </summary>
  25. public override string LocalName
  26. {
  27. get
  28. {
  29. return FattrName;
  30. }
  31. }
  32. /// <summary>
  33. /// Get the qualified attribute name. Attributes do not have an associated namespace.
  34. /// </summary>
  35. public override string Name
  36. {
  37. get
  38. {
  39. return FattrName;
  40. }
  41. }
  42. /// <summary>
  43. /// Override. Returns the node type.
  44. /// </summary>
  45. public override XmlNodeType NodeType
  46. {
  47. get
  48. {
  49. return XmlNodeType.Attribute;
  50. }
  51. }
  52. /// <summary>
  53. /// Retrieve the XmlElement owner of this attribute, or null if attribute not assigned
  54. /// </summary>
  55. public virtual XmlElement OwnerElement
  56. {
  57. get
  58. {
  59. if (FOwnerElement.NodeType == XmlNodeType.Element)
  60. return FOwnerElement as XmlElement;
  61. else
  62. return null;
  63. }
  64. }
  65. /// <summary>
  66. /// Get/Set the value for this node
  67. /// </summary>
  68. public override string Value
  69. {
  70. get
  71. {
  72. return FattrValue;
  73. }
  74. set
  75. {
  76. FattrValue = value;
  77. }
  78. }
  79. //============== Public Methods =============================================
  80. /// <summary>
  81. /// Return a clone of the node
  82. /// </summary>
  83. /// <param name="deep">Make copy of all children</param>
  84. /// <returns>Cloned node</returns>
  85. public override XmlNode CloneNode( bool deep)
  86. {
  87. // TODO - implement XmlAttribute.CloneNode()
  88. throw new NotImplementedException();
  89. }
  90. /// <summary>
  91. /// Saves all children of the current node to the passed writer
  92. /// </summary>
  93. /// <param name="w"></param>
  94. public override void WriteContentTo(XmlWriter w)
  95. {
  96. // TODO - implement XmlAttribute.WriteContentsTo(XmlWriter)
  97. throw new NotImplementedException();
  98. }
  99. /// <summary>
  100. /// Saves the current node to writer w
  101. /// </summary>
  102. /// <param name="w"></param>
  103. public override void WriteTo(XmlWriter w)
  104. {
  105. // TODO - implement XmlAttribute.WriteTo(XmlWriter)
  106. throw new NotImplementedException();
  107. }
  108. // ============ Internal methods ====================================
  109. internal void setOwnerElement( XmlElement newOwnerElement)
  110. {
  111. FOwnerElement = newOwnerElement;
  112. }
  113. // ============ Constructors =========================================
  114. internal XmlAttribute ( XmlDocument aOwner, // owner document
  115. string attributeName, // cannot be ""
  116. string attValue) : base(aOwner)
  117. {
  118. if (aOwner == null)
  119. throw new ArgumentException("Null OwnerDocument passed to XmlAttribute constructor");
  120. if (attributeName.Length == 0)
  121. throw new ArgumentException("Empty string passed to XmlAttribute constructor");
  122. FOwnerElement = null;
  123. FattrName = attributeName;
  124. FattrValue = attValue;
  125. }
  126. }
  127. }