2002-03-11 Duncan Mak <duncan@ximian.com>
[mono.git] / mcs / class / System.XML / System.Xml / XmlElement.cs
index 736c50b5f69d26b7cad5a8c61602778afdf1ef8c..670b514c9f307be8c1bd3bf17123480fb868102b 100644 (file)
-// -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-\r
-//\r
-// System.Xml.XmlElement\r
-//\r
-// Author:\r
-//   Daniel Weber (daniel-weber@austin.rr.com)\r
-//\r
-// (C) 2001 Daniel Weber\r
-using System;\r
-\r
-namespace System.Xml\r
-{\r
-       public class XmlElement : XmlLinkedNode\r
-       {\r
-               // Private/Protected internal data structures\r
-               //===========================================================================\r
-               private XmlAttributeCollection _attributes;\r
-\r
-               // Public Properties\r
-               //===========================================================================\r
-\r
-               /// <summary>\r
-               /// Return the XmlAttributeCollection on the Element\r
-               /// </summary>\r
-               public override XmlAttributeCollection Attributes \r
-               {\r
-                       get\r
-                       {\r
-                               // TODO - implement Attributes\r
-                               return _attributes;\r
-                       }\r
-               }\r
-\r
-\r
-               // Implement abstract methods of XmlNode\r
-               //=====================================================================\r
-               /// <summary>\r
-               /// Return a clone of the node\r
-               /// </summary>\r
-               /// <param name="deep">Make copy of all children</param>\r
-               /// <returns>Cloned node</returns>\r
-               public override XmlNode CloneNode( bool deep)\r
-               {\r
-                       // TODO - implement CloneNode()\r
-                       throw new NotImplementedException();\r
-               }\r
-\r
-               /// <summary>\r
-               /// Saves all children of the current node to the passed writer\r
-               /// </summary>\r
-               /// <param name="w"></param>\r
-               public override void WriteContentTo(XmlWriter w)\r
-               {\r
-                       // TODO - implement WriteContentsTo(XmlWriter)\r
-                       throw new NotImplementedException();\r
-               }\r
-\r
-               /// <summary>\r
-               /// Saves the current node to writer w\r
-               /// </summary>\r
-               /// <param name="w"></param>\r
-               public override void WriteTo(XmlWriter w)\r
-               {\r
-                       // TODO - implement WriteTo(XmlWriter)\r
-                       throw new NotImplementedException();\r
-               }\r
-\r
-               /// <summary>\r
-               /// Returns the local name of the node with qualifiers removed\r
-               /// LocalName of ns:elementName = "elementName"\r
-               /// </summary>\r
-               public override string LocalName \r
-               {\r
-                       get\r
-                       {\r
-                               // TODO - implement LocalName\r
-                               return String.Empty;\r
-                       }\r
-               }\r
-\r
-\r
-               /// <summary>\r
-               /// Get the qualified node name\r
-               /// derived classes must implement as behavior varies\r
-               /// by tag type.\r
-               /// </summary>\r
-               public override string Name \r
-               { \r
-                       get\r
-                       {\r
-                               // TODO - implement Name\r
-                               return String.Empty;\r
-                       }\r
-               }\r
-\r
-               public override XmlNodeType NodeType \r
-               {\r
-                       get\r
-                       {\r
-                               return XmlNodeType.Element;\r
-                       }\r
-               }\r
-\r
-\r
-               // ============= Internal calls =============================================\r
-\r
-               // Constructors\r
-               // ==========================================================================\r
-               internal XmlElement( XmlDocument aOwnerDoc ) : base(aOwnerDoc)\r
-               {\r
-               }\r
-\r
-\r
-               } // class\r
-       }  //namespace\r
+//
+// System.Xml.XmlAttribute
+//
+// Author:
+//   Jason Diamond (jason@injektilo.org)
+//
+// (C) 2002 Jason Diamond  http://injektilo.org/
+//
+
+using System;
+
+namespace System.Xml
+{
+       public class XmlElement : XmlLinkedNode
+       {
+               #region Fields
+
+               private XmlAttributeCollection attributes;
+               private XmlLinkedNode lastLinkedChild;
+               private string localName;
+               private string namespaceURI;
+               private string prefix;
+
+               #endregion
+
+               #region Constructor
+
+               protected internal XmlElement (
+                       string prefix, 
+                       string localName, 
+                       string namespaceURI, 
+                       XmlDocument doc) : base (doc)
+               {
+                       this.prefix = prefix;
+                       this.localName = localName;
+                       this.namespaceURI = namespaceURI;
+
+                       attributes = new XmlAttributeCollection (this);
+               }
+
+               #endregion
+
+               #region Properties
+
+               public override XmlAttributeCollection Attributes {
+                       get { 
+                               return attributes; 
+                       }
+               }
+
+               public virtual bool HasAttributes {
+                       get { 
+                               return attributes.Count > 0; 
+                       }
+               }
+
+               [MonoTODO]
+               public override string InnerText {
+                       get { 
+                               throw new NotImplementedException (); 
+                       }
+
+                       set { 
+                               throw new NotImplementedException (); 
+                       }
+               }
+
+               [MonoTODO]
+               public override string InnerXml {
+                       get { 
+                               throw new NotImplementedException (); 
+                       }
+
+                       set { 
+                               throw new NotImplementedException (); 
+                       }
+               }
+
+               [MonoTODO]
+               public bool IsEmpty     {
+                       get { 
+                               throw new NotImplementedException (); 
+                       }
+
+                       set { 
+                               throw new NotImplementedException (); 
+                       }
+               }
+
+               internal override XmlLinkedNode LastLinkedChild {
+                       get     {
+                               return lastLinkedChild;
+                       }
+
+                       set {
+                               lastLinkedChild = value;
+                       }
+               }
+               
+               public override string LocalName 
+               {
+                       get { 
+                               return localName; 
+                       }
+               }
+
+               public override string Name {
+                       get { 
+                               return prefix != String.Empty ? prefix + ":" + localName : localName; 
+                       }
+               }
+
+               public override string NamespaceURI {
+                       get { 
+                               return namespaceURI; 
+                       }
+               }
+
+               [MonoTODO]
+               public override XmlNode NextSibling {
+                       get { 
+                               return base.NextSibling; 
+                       }
+               }
+
+               public override XmlNodeType NodeType {
+                       get { 
+                               return XmlNodeType.Element; 
+                       }
+               }
+
+               [MonoTODO]
+               public override XmlDocument OwnerDocument {
+                       get { 
+                               return base.OwnerDocument; 
+                       }
+               }
+
+               public override string Prefix {
+                       get { 
+                               return prefix; 
+                       }
+               }
+
+               #endregion
+
+               #region Methods
+
+               [MonoTODO]
+               public override XmlNode CloneNode (bool deep)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               [MonoTODO]
+               public virtual string GetAttribute (string name)
+               {
+                       XmlNode attributeNode = Attributes.GetNamedItem (name);
+                       return attributeNode != null ? attributeNode.Value : String.Empty;
+               }
+
+               [MonoTODO]
+               public virtual string GetAttribute (string localName, string namespaceURI)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               [MonoTODO]
+               public virtual XmlAttribute GetAttributeNode (string name)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               [MonoTODO]
+               public virtual XmlAttribute GetAttributeNode (string localName, string namespaceURI)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               [MonoTODO]
+               public virtual XmlNodeList GetElementsByTagName (string name)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               [MonoTODO]
+               public virtual XmlNodeList GetElementsByTagName (string localName, string namespaceURI)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               [MonoTODO]
+               public virtual bool HasAttribute (string name)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               [MonoTODO]
+               public virtual bool HasAttribute (string localName, string namespaceURI)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               [MonoTODO ("Don't remove default attributes.")]
+               public override void RemoveAll ()
+               {
+                       // Remove the child nodes.
+                       base.RemoveAll ();
+
+                       // Remove all attributes.
+                       attributes.RemoveAll ();
+               }
+
+               [MonoTODO]
+               public virtual void RemoveAllAttributes ()
+               {
+                       throw new NotImplementedException ();
+               }
+
+               [MonoTODO]
+               public virtual void RemoveAttribute (string name)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               [MonoTODO]
+               public virtual void RemoveAttribute (string localName, string namespaceURI)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               [MonoTODO]
+               public virtual XmlNode RemoveAttributeAt (int i)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               [MonoTODO]
+               public virtual XmlAttribute RemoveAttributeNode (XmlAttribute oldAttr)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               [MonoTODO]
+               public virtual XmlAttribute RemoveAttributeNode (string localName, string namespaceURI)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               [MonoTODO]
+               public virtual void SetAttribute (string name, string value)
+               {
+                       XmlAttribute attribute = OwnerDocument.CreateAttribute (name);
+                       attribute.SetOwnerElement (this);
+                       attribute.Value = value;
+                       Attributes.SetNamedItem (attribute);
+               }
+
+               [MonoTODO]
+               public virtual void SetAttribute (string localName, string namespaceURI, string value)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               [MonoTODO]
+               public virtual XmlAttribute SetAttributeNode (XmlAttribute newAttr)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               [MonoTODO]
+               public virtual XmlAttribute SetAttributeNode (string localName, string namespaceURI)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               [MonoTODO]
+               public override void WriteContentTo (XmlWriter w)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               [MonoTODO]
+               public override void WriteTo (XmlWriter w)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               #endregion
+       }
+}