Implementation and tests for XmlAttributeCollection.RemoveAll and XmlElement.RemoveAl...
[mono.git] / mcs / class / System.XML / System.Xml / XmlAttribute.cs
index 6a86c71ac16e1abf74bad433fa1c37a75f68014b..70419b6c593c70b7864440412916865ba1eb7f26 100644 (file)
-// -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
 //
 // System.Xml.XmlAttribute
 //
 // Author:
-//   Daniel Weber (daniel-weber@austin.rr.com)
+//   Jason Diamond (jason@injektilo.org)
+//
+// (C) 2002 Jason Diamond  http://injektilo.org/
 //
-// (C) 2001 Daniel Weber
 
 using System;
 
 namespace System.Xml
 {
-       /// <summary>
-       /// Summary description for XmlAttribute.
-       /// </summary>
        public class XmlAttribute : XmlNode
        {
-               // ============  private data structures ==============================
-               private XmlNode FOwnerElement;
-               
-               string FattrName;
-               string FattrValue;
-               
-               //==== Public Properties ====================================================
-
-               /// <summary>
-               /// Returns the local name of the attribute.  For attributes, this is the same as Name
-               /// </summary>
-               public override string LocalName 
+               #region Fields
+
+               private XmlLinkedNode lastChild;
+               private string localName;
+               private string namespaceURI;
+               private string prefix;
+
+               #endregion
+
+               #region Constructor
+
+               [MonoTODO("need to set namespaceURI if prefix is recognized built-in ones like xmlns")]
+               protected internal XmlAttribute (
+                       string prefix, 
+                       string localName, 
+                       string namespaceURI, 
+                       XmlDocument doc) : base (doc)
                {
-                       get
-                       {
-                               return FattrName;
+                       this.prefix = prefix;
+                       this.localName = localName;
+                       this.namespaceURI = namespaceURI;
+               }
+
+               #endregion
+
+               #region Properties
+
+               public override string BaseURI {
+                       get {
+                               return OwnerElement.BaseURI;
                        }
                }
 
-               /// <summary>
-               /// Get the qualified attribute name.  Attributes do not have an associated namespace.
-               /// </summary>
-               public override string Name 
-               { 
-                       get
-                       {
-                               return FattrName;
+               [MonoTODO]
+               public override string InnerText {
+                       get {
+                               throw new NotImplementedException ();
+                       }
+
+                       set {
+                               throw new NotImplementedException ();
                        }
                }
 
-               /// <summary>
-               /// Override.  Returns the node type.
-               /// </summary>
-               public override XmlNodeType NodeType 
-               {
-                       get
-                       {
+               [MonoTODO ("Setter.")]
+               public override string InnerXml {
+                       get {
+                               // Not sure why this is an override.  Passing through for now.
+                               return base.InnerXml;
+                       }
+
+                       set {
+                               throw new NotImplementedException ();
+                       }
+               }
+
+               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;
+                       }
+               }
+
+               public override XmlNodeType NodeType {
+                       get {
                                return XmlNodeType.Attribute;
                        }
                }
 
-               /// <summary>
-               /// Retrieve the XmlElement owner of this attribute, or null if attribute not assigned
-               /// </summary>
-               public virtual XmlElement OwnerElement
-               {
-                       get
-                       {
-                               if (FOwnerElement.NodeType == XmlNodeType.Element)
-                                       return FOwnerElement as XmlElement;
-                               else
-                                       return null;
+               public override XmlDocument OwnerDocument {
+                       get {
+                               return base.OwnerDocument;
                        }
                }
 
-               /// <summary>
-               /// Get/Set the value for this node
-               /// </summary>
-               public override string Value 
-               {
-                       get
-                       {
-                               return FattrValue;
+               public virtual XmlElement OwnerElement {
+                       get {
+                               return base.ParentNode as XmlElement;
+                       }
+               }
+
+               [MonoTODO]
+               public override XmlNode ParentNode {
+                       get {
+                               return null;
+                       }
+               }
+
+               [MonoTODO]
+               // We gotta do more in the set block here
+               // We need to do the proper tests and throw
+               // the correct Exceptions
+               public override string Prefix {
+                       set {
+                               prefix = value;
                        }
                        
-                       set
-                       {
-                               FattrValue = value;
+                       get {
+                               return prefix;
+                       }
+               }
+
+               [MonoTODO]
+               public virtual bool Specified {
+                       get {
+                               throw new NotImplementedException ();
                        }
                }
 
-               //============== Public Methods =============================================
+               public override string Value {
+                       get {
+                               XmlNode firstChild = FirstChild;
+                               if (firstChild == null)
+                                       return String.Empty;
+                               return firstChild.Value;
+                       }
 
-               /// <summary>
-               /// Return a clone of the node
-               /// </summary>
-               /// <param name="deep">Make copy of all children</param>
-               /// <returns>Cloned node</returns>
-               public override XmlNode CloneNode( bool deep)
-               {
-                       // TODO - implement XmlAttribute.CloneNode()
-                       throw new NotImplementedException();
+                       set {
+                               XmlNode firstChild = FirstChild;
+                               if (firstChild == null)
+                                       AppendChild (OwnerDocument.CreateTextNode (value));
+                               else
+                                       firstChild.Value = value;
+                       }
                }
 
-               /// <summary>
-               /// Saves all children of the current node to the passed writer
-               /// </summary>
-               /// <param name="w"></param>
-               public override void WriteContentTo(XmlWriter w)
+               #endregion
+
+               #region Methods
+
+               public override XmlNode CloneNode (bool deep)
                {
-                       // TODO - implement XmlAttribute.WriteContentsTo(XmlWriter)
-                       throw new NotImplementedException();
+                       XmlNode node = new XmlAttribute (prefix, localName, namespaceURI,
+                                                        OwnerDocument);
+                       if (deep) {
+                               while ((node != null) && (node.HasChildNodes)) {
+                                       AppendChild (node.NextSibling.CloneNode (true));
+                                       node = node.NextSibling;
+                               }
+                       }
+
+                       return node;
                }
 
-               /// <summary>
-               /// Saves the current node to writer w
-               /// </summary>
-               /// <param name="w"></param>
-               public override void WriteTo(XmlWriter w)
+               public override void WriteContentTo (XmlWriter w)
                {
-                       // TODO - implement XmlAttribute.WriteTo(XmlWriter)
-                       throw new NotImplementedException();
+                       w.WriteString (Value);
                }
 
-               // ============  Internal methods  ====================================
-               internal void setOwnerElement( XmlElement newOwnerElement)
+               public override void WriteTo (XmlWriter w)
                {
-                       FOwnerElement = newOwnerElement;
+                       w.WriteAttributeString (prefix, localName, namespaceURI, Value);
                }
 
-               // ============  Constructors =========================================
-               internal XmlAttribute ( XmlDocument aOwner,                     // owner document
-                       string attributeName,                                                   // cannot be ""
-                       string attValue) : base(aOwner)
-               {
-                       if (aOwner == null)
-                               throw new ArgumentException("Null OwnerDocument passed to XmlAttribute constructor");
-                       if (attributeName.Length == 0)
-                               throw new ArgumentException("Empty string passed to XmlAttribute constructor");
+               #endregion
 
-                       FOwnerElement = null;
-                       FattrName = attributeName;
-                       FattrValue = attValue;
-               }
-       
+               internal override XmlLinkedNode LastLinkedChild {
+                       get { return lastChild; }
 
+                       set { lastChild = value; }
+               }
        }
 }