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