2 // System.Xml.XmlAttribute
5 // Jason Diamond (jason@injektilo.org)
7 // (C) 2002 Jason Diamond http://injektilo.org/
11 using System.Collections;
15 public class XmlElement : XmlLinkedNode
19 private XmlAttributeCollection attributes;
20 private XmlLinkedNode lastLinkedChild;
21 private string localName;
22 private string namespaceURI;
23 private string prefix;
24 private string node_value;
30 protected internal XmlElement (
34 XmlDocument doc) : base (doc)
37 this.localName = localName;
38 this.namespaceURI = namespaceURI;
40 attributes = new XmlAttributeCollection (this);
47 public override XmlAttributeCollection Attributes {
48 get { return attributes; }
51 public virtual bool HasAttributes {
52 get { return attributes.Count > 0; }
55 [MonoTODO ("Setter.")]
56 public override string InnerXml {
58 // Not sure why this is an override. Passing through for now.
61 set { throw new NotImplementedException (); }
66 get { throw new NotImplementedException (); }
68 set { throw new NotImplementedException (); }
71 internal override XmlLinkedNode LastLinkedChild {
72 get { return lastLinkedChild; }
74 set { lastLinkedChild = value; }
77 public override string LocalName {
78 get { return localName; }
81 public override string Name {
83 return prefix != String.Empty ? prefix + ":" + localName : localName;
87 public override string NamespaceURI {
88 get { return namespaceURI; }
92 public override XmlNode NextSibling {
94 return base.NextSibling;
98 public override XmlNodeType NodeType {
100 return XmlNodeType.Element;
105 public override XmlDocument OwnerDocument {
107 return base.OwnerDocument;
111 public override string Prefix {
117 public override string Value {
132 public override XmlNode CloneNode (bool deep)
134 XmlNode node = new XmlElement (prefix, localName, namespaceURI,
137 for (int i = 0; i < node.Attributes.Count; i++)
138 node.AppendChild (node.Attributes [i].CloneNode (false));
141 while ((node != null) && (node.HasChildNodes)) {
142 AppendChild (node.NextSibling.CloneNode (true));
143 node = node.NextSibling;
148 // Reminder: Also look into Default attributes.
154 public virtual string GetAttribute (string name)
156 XmlNode attributeNode = Attributes.GetNamedItem (name);
157 return attributeNode != null ? attributeNode.Value : String.Empty;
161 public virtual string GetAttribute (string localName, string namespaceURI)
163 XmlNode attributeNode = Attributes.GetNamedItem (localName, namespaceURI);
164 return attributeNode != null ? attributeNode.Value : String.Empty;
168 public virtual XmlAttribute GetAttributeNode (string name)
170 XmlNode attributeNode = Attributes.GetNamedItem (name);
171 return attributeNode != null ? attributeNode as XmlAttribute : null;
175 public virtual XmlAttribute GetAttributeNode (string localName, string namespaceURI)
177 XmlNode attributeNode = Attributes.GetNamedItem (localName, namespaceURI);
178 return attributeNode != null ? attributeNode as XmlAttribute : null;
181 public virtual XmlNodeList GetElementsByTagName (string name)
183 ArrayList nodeArrayList = new ArrayList ();
184 this.searchNodesRecursively (this, name, String.Empty, nodeArrayList);
185 return new XmlNodeArrayList (nodeArrayList);
188 private void searchNodesRecursively (XmlNode argNode, string argName, string argNamespaceURI,
189 ArrayList argArrayList)
191 XmlNodeList xmlNodeList = argNode.ChildNodes;
192 foreach (XmlNode node in xmlNodeList)
194 if (node.LocalName.Equals (argName) && node.NamespaceURI.Equals (argNamespaceURI))
195 argArrayList.Add (node);
197 this.searchNodesRecursively (node, argName, argNamespaceURI, argArrayList);
202 public virtual bool HasAttribute (string name)
204 XmlNode attributeNode = Attributes.GetNamedItem (name);
205 return attributeNode != null;
209 public virtual bool HasAttribute (string localName, string namespaceURI)
211 throw new NotImplementedException ();
214 [MonoTODO ("Don't remove default attributes.")]
215 public override void RemoveAll ()
217 // Remove the child nodes.
220 // Remove all attributes.
221 attributes.RemoveAll ();
225 public virtual void RemoveAllAttributes ()
227 throw new NotImplementedException ();
231 public virtual void RemoveAttribute (string name)
233 throw new NotImplementedException ();
237 public virtual void RemoveAttribute (string localName, string namespaceURI)
239 throw new NotImplementedException ();
243 public virtual XmlNode RemoveAttributeAt (int i)
245 throw new NotImplementedException ();
249 public virtual XmlAttribute RemoveAttributeNode (XmlAttribute oldAttr)
251 throw new NotImplementedException ();
255 public virtual XmlAttribute RemoveAttributeNode (string localName, string namespaceURI)
257 throw new NotImplementedException ();
261 public virtual void SetAttribute (string name, string value)
263 XmlAttribute attribute = OwnerDocument.CreateAttribute (name);
264 attribute.SetParentNode (this);
265 attribute.Value = value;
266 Attributes.SetNamedItem (attribute);
270 public virtual string SetAttribute (string localName, string namespaceURI, string value)
272 throw new NotImplementedException ();
276 public virtual XmlAttribute SetAttributeNode (XmlAttribute newAttr)
278 newAttr.SetParentNode(this);
279 XmlNode oldAttr = Attributes.SetNamedItem(newAttr);
280 return oldAttr != null ? oldAttr as XmlAttribute : null;
284 public virtual XmlAttribute SetAttributeNode (string localName, string namespaceURI)
286 throw new NotImplementedException ();
289 public override void WriteContentTo (XmlWriter w)
291 foreach(XmlNode childNode in ChildNodes)
292 childNode.WriteTo(w);
295 public override void WriteTo (XmlWriter w)
297 w.WriteStartElement(Prefix, LocalName, NamespaceURI);
299 foreach(XmlNode attributeNode in Attributes)
300 attributeNode.WriteTo(w);