Fixed MoveToParent issues with the navigator and attributes.
[mono.git] / mcs / class / System.XML / System.Xml / XmlAttribute.cs
1 //
2 // System.Xml.XmlAttribute
3 //
4 // Author:
5 //   Jason Diamond (jason@injektilo.org)
6 //
7 // (C) 2002 Jason Diamond  http://injektilo.org/
8 //
9
10 using System;
11
12 namespace System.Xml
13 {
14         public class XmlAttribute : XmlNode
15         {
16                 #region Fields
17
18                 private XmlLinkedNode lastChild;
19                 private string localName;
20                 private string namespaceURI;
21                 private string prefix;
22
23                 #endregion
24
25                 #region Constructor
26
27                 [MonoTODO("need to set namespaceURI if prefix is recognized built-in ones like xmlns")]
28                 protected internal XmlAttribute (
29                         string prefix, 
30                         string localName, 
31                         string namespaceURI, 
32                         XmlDocument doc) : base (doc)
33                 {
34                         this.prefix = prefix;
35                         this.localName = localName;
36                         this.namespaceURI = namespaceURI;
37                 }
38
39                 #endregion
40
41                 #region Properties
42
43                 public override string BaseURI {
44                         get {
45                                 return OwnerElement.BaseURI;
46                         }
47                 }
48
49                 [MonoTODO]
50                 public override string InnerText {
51                         get {
52                                 throw new NotImplementedException ();
53                         }
54
55                         set {
56                                 throw new NotImplementedException ();
57                         }
58                 }
59
60                 [MonoTODO ("Setter.")]
61                 public override string InnerXml {
62                         get {
63                                 // Not sure why this is an override.  Passing through for now.
64                                 return base.InnerXml;
65                         }
66
67                         set {
68                                 throw new NotImplementedException ();
69                         }
70                 }
71
72                 public override string LocalName {
73                         get {
74                                 return localName;
75                         }
76                 }
77
78                 public override string Name {
79                         get { 
80                                 return prefix != String.Empty ? prefix + ":" + localName : localName; 
81                         }
82                 }
83
84                 public override string NamespaceURI {
85                         get {
86                                 return namespaceURI;
87                         }
88                 }
89
90                 public override XmlNodeType NodeType {
91                         get {
92                                 return XmlNodeType.Attribute;
93                         }
94                 }
95
96                 public override XmlDocument OwnerDocument {
97                         get {
98                                 return base.OwnerDocument;
99                         }
100                 }
101
102                 public virtual XmlElement OwnerElement {
103                         get {
104                                 return base.ParentNode as XmlElement;
105                         }
106                 }
107
108                 [MonoTODO]
109                 public override XmlNode ParentNode {
110                         get {
111                                 return null;
112                         }
113                 }
114
115                 [MonoTODO]
116                 // We gotta do more in the set block here
117                 // We need to do the proper tests and throw
118                 // the correct Exceptions
119                 public override string Prefix {
120                         set {
121                                 prefix = value;
122                         }
123                         
124                         get {
125                                 return prefix;
126                         }
127                 }
128
129                 [MonoTODO]
130                 public virtual bool Specified {
131                         get {
132                                 throw new NotImplementedException ();
133                         }
134                 }
135
136                 public override string Value {
137                         get {
138                                 XmlNode firstChild = FirstChild;
139                                 if (firstChild == null)
140                                         return String.Empty;
141                                 return firstChild.Value;
142                         }
143
144                         set {
145                                 XmlNode firstChild = FirstChild;
146                                 if (firstChild == null)
147                                         AppendChild (OwnerDocument.CreateTextNode (value));
148                                 else
149                                         firstChild.Value = value;
150                         }
151                 }
152
153                 #endregion
154
155                 #region Methods
156
157                 public override XmlNode CloneNode (bool deep)
158                 {
159                         XmlNode node = new XmlAttribute (prefix, localName, namespaceURI,
160                                                          OwnerDocument);
161                         if (deep) {
162                                 while ((node != null) && (node.HasChildNodes)) {
163                                         AppendChild (node.NextSibling.CloneNode (true));
164                                         node = node.NextSibling;
165                                 }
166                         }
167
168                         return node;
169                 }
170
171                 public override void WriteContentTo (XmlWriter w)
172                 {
173                         w.WriteString (Value);
174                 }
175
176                 public override void WriteTo (XmlWriter w)
177                 {
178                         w.WriteAttributeString (prefix, localName, namespaceURI, Value);
179                 }
180
181                 #endregion
182
183                 internal override XmlLinkedNode LastLinkedChild {
184                         get { return lastChild; }
185
186                         set { lastChild = value; }
187                 }
188         }
189 }