2 // System.Xml.XmlAttribute
5 // Jason Diamond (jason@injektilo.org)
7 // (C) 2002 Jason Diamond http://injektilo.org/
14 public class XmlElement : XmlLinkedNode
18 private XmlAttributeCollection attributes;
19 private XmlLinkedNode lastLinkedChild;
20 private string localName;
21 private string namespaceURI;
22 private string prefix;
28 protected internal XmlElement (
32 XmlDocument doc) : base (doc)
35 this.localName = localName;
36 this.namespaceURI = namespaceURI;
38 attributes = new XmlAttributeCollection (this);
45 public override XmlAttributeCollection Attributes {
46 get { return attributes; }
49 public virtual bool HasAttributes {
50 get { return attributes.Count > 0; }
54 public override string InnerText {
55 get { throw new NotImplementedException (); }
57 set { throw new NotImplementedException (); }
60 [MonoTODO ("Setter.")]
61 public override string InnerXml {
63 // Not sure why this is an override. Passing through for now.
66 set { throw new NotImplementedException (); }
71 get { throw new NotImplementedException (); }
73 set { throw new NotImplementedException (); }
76 internal override XmlLinkedNode LastLinkedChild {
77 get { return lastLinkedChild; }
79 set { lastLinkedChild = value; }
82 public override string LocalName {
83 get { return localName; }
86 public override string Name {
88 return prefix != String.Empty ? prefix + ":" + localName : localName;
92 public override string NamespaceURI {
93 get { return namespaceURI; }
97 public override XmlNode NextSibling {
99 return base.NextSibling;
103 public override XmlNodeType NodeType {
105 return XmlNodeType.Element;
110 public override XmlDocument OwnerDocument {
112 return base.OwnerDocument;
116 public override string Prefix {
127 public override XmlNode CloneNode (bool deep)
129 XmlNode node = new XmlElement (prefix, localName, namespaceURI,
132 for (int i = 0; i < node.Attributes.Count; i++)
133 node.AppendChild (node.Attributes [i].CloneNode (false));
136 while ((node != null) && (node.HasChildNodes)) {
137 AppendChild (node.NextSibling.CloneNode (true));
138 node = node.NextSibling;
143 // Reminder: Also look into Default attributes.
149 public virtual string GetAttribute (string name)
151 XmlNode attributeNode = Attributes.GetNamedItem (name);
152 return attributeNode != null ? attributeNode.Value : String.Empty;
156 public virtual string GetAttribute (string localName, string namespaceURI)
158 throw new NotImplementedException ();
162 public virtual XmlAttribute GetAttributeNode (string name)
164 throw new NotImplementedException ();
168 public virtual XmlAttribute GetAttributeNode (string localName, string namespaceURI)
170 throw new NotImplementedException ();
174 public virtual XmlNodeList GetElementsByTagName (string name)
176 throw new NotImplementedException ();
180 public virtual XmlNodeList GetElementsByTagName (string localName, string namespaceURI)
182 throw new NotImplementedException ();
186 public virtual bool HasAttribute (string name)
188 XmlNode attributeNode = Attributes.GetNamedItem (name);
189 return attributeNode != null;
193 public virtual bool HasAttribute (string localName, string namespaceURI)
195 throw new NotImplementedException ();
198 [MonoTODO ("Don't remove default attributes.")]
199 public override void RemoveAll ()
201 // Remove the child nodes.
204 // Remove all attributes.
205 attributes.RemoveAll ();
209 public virtual void RemoveAllAttributes ()
211 throw new NotImplementedException ();
215 public virtual void RemoveAttribute (string name)
217 throw new NotImplementedException ();
221 public virtual void RemoveAttribute (string localName, string namespaceURI)
223 throw new NotImplementedException ();
227 public virtual XmlNode RemoveAttributeAt (int i)
229 throw new NotImplementedException ();
233 public virtual XmlAttribute RemoveAttributeNode (XmlAttribute oldAttr)
235 throw new NotImplementedException ();
239 public virtual XmlAttribute RemoveAttributeNode (string localName, string namespaceURI)
241 throw new NotImplementedException ();
245 public virtual void SetAttribute (string name, string value)
247 XmlAttribute attribute = OwnerDocument.CreateAttribute (name);
248 attribute.SetOwnerElement (this);
249 attribute.Value = value;
250 Attributes.SetNamedItem (attribute);
254 public virtual string SetAttribute (string localName, string namespaceURI, string value)
256 throw new NotImplementedException ();
260 public virtual XmlAttribute SetAttributeNode (XmlAttribute newAttr)
262 throw new NotImplementedException ();
266 public virtual XmlAttribute SetAttributeNode (string localName, string namespaceURI)
268 throw new NotImplementedException ();
271 public override void WriteContentTo (XmlWriter w)
273 foreach(XmlNode childNode in ChildNodes)
274 childNode.WriteTo(w);
277 public override void WriteTo (XmlWriter w)
279 w.WriteStartElement(LocalName);
281 foreach(XmlNode attributeNode in Attributes)
282 attributeNode.WriteTo(w);