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 (); }
61 public override string InnerXml {
62 get { throw new NotImplementedException (); }
64 set { throw new NotImplementedException (); }
69 get { throw new NotImplementedException (); }
71 set { throw new NotImplementedException (); }
74 internal override XmlLinkedNode LastLinkedChild {
75 get { return lastLinkedChild; }
77 set { lastLinkedChild = value; }
80 public override string LocalName {
81 get { return localName; }
84 public override string Name {
86 return prefix != String.Empty ? prefix + ":" + localName : localName;
90 public override string NamespaceURI {
91 get { return namespaceURI; }
95 public override XmlNode NextSibling {
97 return base.NextSibling;
101 public override XmlNodeType NodeType {
103 return XmlNodeType.Element;
108 public override XmlDocument OwnerDocument {
110 return base.OwnerDocument;
114 public override string Prefix {
125 public override XmlNode CloneNode (bool deep)
127 XmlNode node = new XmlElement (prefix, localName, namespaceURI,
130 for (int i = 0; i < node.Attributes.Count; i++)
131 node.AppendChild (node.Attributes [i].CloneNode (false));
134 while ((node != null) && (node.HasChildNodes)) {
135 AppendChild (node.NextSibling.CloneNode (true));
136 node = node.NextSibling;
141 // Reminder: Also look into Default attributes.
147 public virtual string GetAttribute (string name)
149 XmlNode attributeNode = Attributes.GetNamedItem (name);
150 return attributeNode != null ? attributeNode.Value : String.Empty;
154 public virtual string GetAttribute (string localName, string namespaceURI)
156 throw new NotImplementedException ();
160 public virtual XmlAttribute GetAttributeNode (string name)
162 throw new NotImplementedException ();
166 public virtual XmlAttribute GetAttributeNode (string localName, string namespaceURI)
168 throw new NotImplementedException ();
172 public virtual XmlNodeList GetElementsByTagName (string name)
174 throw new NotImplementedException ();
178 public virtual XmlNodeList GetElementsByTagName (string localName, string namespaceURI)
180 throw new NotImplementedException ();
184 public virtual bool HasAttribute (string name)
186 XmlNode attributeNode = Attributes.GetNamedItem (name);
187 return attributeNode != null;
191 public virtual bool HasAttribute (string localName, string namespaceURI)
193 throw new NotImplementedException ();
196 [MonoTODO ("Don't remove default attributes.")]
197 public override void RemoveAll ()
199 // Remove the child nodes.
202 // Remove all attributes.
203 attributes.RemoveAll ();
207 public virtual void RemoveAllAttributes ()
209 throw new NotImplementedException ();
213 public virtual void RemoveAttribute (string name)
215 throw new NotImplementedException ();
219 public virtual void RemoveAttribute (string localName, string namespaceURI)
221 throw new NotImplementedException ();
225 public virtual XmlNode RemoveAttributeAt (int i)
227 throw new NotImplementedException ();
231 public virtual XmlAttribute RemoveAttributeNode (XmlAttribute oldAttr)
233 throw new NotImplementedException ();
237 public virtual XmlAttribute RemoveAttributeNode (string localName, string namespaceURI)
239 throw new NotImplementedException ();
243 public virtual void SetAttribute (string name, string value)
245 XmlAttribute attribute = OwnerDocument.CreateAttribute (name);
246 attribute.SetOwnerElement (this);
247 attribute.Value = value;
248 Attributes.SetNamedItem (attribute);
252 public virtual string SetAttribute (string localName, string namespaceURI, string value)
254 throw new NotImplementedException ();
258 public virtual XmlAttribute SetAttributeNode (XmlAttribute newAttr)
260 throw new NotImplementedException ();
264 public virtual XmlAttribute SetAttributeNode (string localName, string namespaceURI)
266 throw new NotImplementedException ();
269 public override void WriteContentTo (XmlWriter w)
271 foreach(XmlNode childNode in ChildNodes)
272 childNode.WriteTo(w);
275 public override void WriteTo (XmlWriter w)
277 w.WriteStartElement(LocalName);
279 foreach(XmlNode attributeNode in Attributes)
280 attributeNode.WriteTo(w);