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; }
53 [MonoTODO ("Setter.")]
54 public override string InnerXml {
56 // Not sure why this is an override. Passing through for now.
59 set { throw new NotImplementedException (); }
64 get { throw new NotImplementedException (); }
66 set { throw new NotImplementedException (); }
69 internal override XmlLinkedNode LastLinkedChild {
70 get { return lastLinkedChild; }
72 set { lastLinkedChild = value; }
75 public override string LocalName {
76 get { return localName; }
79 public override string Name {
81 return prefix != String.Empty ? prefix + ":" + localName : localName;
85 public override string NamespaceURI {
86 get { return namespaceURI; }
90 public override XmlNode NextSibling {
92 return base.NextSibling;
96 public override XmlNodeType NodeType {
98 return XmlNodeType.Element;
103 public override XmlDocument OwnerDocument {
105 return base.OwnerDocument;
109 public override string Prefix {
120 public override XmlNode CloneNode (bool deep)
122 XmlNode node = new XmlElement (prefix, localName, namespaceURI,
125 for (int i = 0; i < node.Attributes.Count; i++)
126 node.AppendChild (node.Attributes [i].CloneNode (false));
129 while ((node != null) && (node.HasChildNodes)) {
130 AppendChild (node.NextSibling.CloneNode (true));
131 node = node.NextSibling;
136 // Reminder: Also look into Default attributes.
142 public virtual string GetAttribute (string name)
144 XmlNode attributeNode = Attributes.GetNamedItem (name);
145 return attributeNode != null ? attributeNode.Value : String.Empty;
149 public virtual string GetAttribute (string localName, string namespaceURI)
151 XmlNode attributeNode = Attributes.GetNamedItem (localName, namespaceURI);
152 return attributeNode != null ? attributeNode.Value : String.Empty;
156 public virtual XmlAttribute GetAttributeNode (string name)
158 XmlNode attributeNode = Attributes.GetNamedItem (name);
159 return attributeNode != null ? attributeNode as XmlAttribute : null;
163 public virtual XmlAttribute GetAttributeNode (string localName, string namespaceURI)
165 XmlNode attributeNode = Attributes.GetNamedItem (localName, namespaceURI);
166 return attributeNode != null ? attributeNode as XmlAttribute : null;
170 public virtual XmlNodeList GetElementsByTagName (string name)
172 throw new NotImplementedException ();
176 public virtual XmlNodeList GetElementsByTagName (string localName, string namespaceURI)
178 throw new NotImplementedException ();
182 public virtual bool HasAttribute (string name)
184 XmlNode attributeNode = Attributes.GetNamedItem (name);
185 return attributeNode != null;
189 public virtual bool HasAttribute (string localName, string namespaceURI)
191 throw new NotImplementedException ();
194 [MonoTODO ("Don't remove default attributes.")]
195 public override void RemoveAll ()
197 // Remove the child nodes.
200 // Remove all attributes.
201 attributes.RemoveAll ();
205 public virtual void RemoveAllAttributes ()
207 throw new NotImplementedException ();
211 public virtual void RemoveAttribute (string name)
213 throw new NotImplementedException ();
217 public virtual void RemoveAttribute (string localName, string namespaceURI)
219 throw new NotImplementedException ();
223 public virtual XmlNode RemoveAttributeAt (int i)
225 throw new NotImplementedException ();
229 public virtual XmlAttribute RemoveAttributeNode (XmlAttribute oldAttr)
231 throw new NotImplementedException ();
235 public virtual XmlAttribute RemoveAttributeNode (string localName, string namespaceURI)
237 throw new NotImplementedException ();
241 public virtual void SetAttribute (string name, string value)
243 XmlAttribute attribute = OwnerDocument.CreateAttribute (name);
244 attribute.SetParentNode (this);
245 attribute.Value = value;
246 Attributes.SetNamedItem (attribute);
250 public virtual string SetAttribute (string localName, string namespaceURI, string value)
252 throw new NotImplementedException ();
256 public virtual XmlAttribute SetAttributeNode (XmlAttribute newAttr)
258 newAttr.SetParentNode(this);
259 XmlNode oldAttr = Attributes.SetNamedItem(newAttr);
260 return oldAttr != null ? oldAttr as XmlAttribute : null;
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(Prefix, LocalName, NamespaceURI);
279 foreach(XmlNode attributeNode in Attributes)
280 attributeNode.WriteTo(w);