2002-12-24 Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
[mono.git] / mcs / class / System.XML / System.Xml / XmlAttribute.cs
index 56e8658f4d5f13187d0c6929b9e87d3a117254d9..167a9b18abaa60b57bf42f77ff0c7ad41b2a06ba 100644 (file)
@@ -9,6 +9,7 @@
 
 using System;
 using System.Text;
+using System.Xml.XPath;
 
 namespace System.Xml
 {
@@ -20,6 +21,8 @@ namespace System.Xml
                private string localName;
                private string namespaceURI;
                private string prefix;
+               internal bool isDefault;
+               private XmlElement ownerElement;
 
                #endregion
 
@@ -32,6 +35,8 @@ namespace System.Xml
                        string namespaceURI, 
                        XmlDocument doc) : base (doc)
                {
+                       // What to be recognized is: xml:space, xml:lang, xml:base, and
+                       // xmlns and xmlns:* (when XmlDocument.Namespaces = true only)
                        this.prefix = prefix;
                        this.localName = localName;
                        this.namespaceURI = namespaceURI;
@@ -47,7 +52,6 @@ namespace System.Xml
                        }
                }
 
-               [MonoTODO ("Setter")]
                public override string InnerText {
                        get {
                                StringBuilder builder = new StringBuilder ();
@@ -56,7 +60,7 @@ namespace System.Xml
                         }
 
                        set {
-                               throw new NotImplementedException ();
+                               Value = value;
                        }
                }
 
@@ -71,7 +75,7 @@ namespace System.Xml
                         }
                 }
                
-               [MonoTODO ("Setter.")]
+               [MonoTODO ("Setter is incomplete(XmlTextReader.ReadAttribute is incomplete;No resolution for xml:lang/space")]
                public override string InnerXml {
                        get {
                                // Not sure why this is an override.  Passing through for now.
@@ -79,7 +83,13 @@ namespace System.Xml
                        }
 
                        set {
-                               throw new NotImplementedException ();
+                               XmlNamespaceManager nsmgr = ConstructNamespaceManager ();
+                               XmlParserContext ctx = new XmlParserContext (OwnerDocument.NameTable, nsmgr, XmlLang, this.XmlSpace);
+                               XmlTextReader xtr = OwnerDocument.ReusableReader;
+                               xtr.SetReaderContext (BaseURI, ctx);
+                               xtr.SetReaderFragment (new System.IO.StringReader ("'" + value.Replace ("'", "&apos;") + "'"), XmlNodeType.Attribute);
+
+                               OwnerDocument.ReadAttributeNodeValue (xtr, this);
                        }
                }
 
@@ -107,6 +117,12 @@ namespace System.Xml
                        }
                }
 
+               internal override XPathNodeType XPathNodeType {
+                       get {
+                               return XPathNodeType.Attribute;
+                       }
+               }
+
                public override XmlDocument OwnerDocument {
                        get {
                                return base.OwnerDocument;
@@ -115,23 +131,35 @@ namespace System.Xml
 
                public virtual XmlElement OwnerElement {
                        get {
-                               return base.ParentNode as XmlElement;
+                               return ownerElement;
                        }
                }
 
-               [MonoTODO]
                public override XmlNode ParentNode {
                        get {
+                               // It always returns null (by specification).
                                return null;
                        }
                }
 
-               [MonoTODO]
+               [MonoTODO("setter incomplete (name character check, format check, wrong prefix&nsURI)")]
                // We gotta do more in the set block here
                // We need to do the proper tests and throw
                // the correct Exceptions
+               //
+               // Wrong cases are: (1)check readonly, (2)check character validity,
+               // (3)check format validity, (4)this is attribute and qualifiedName != "xmlns"
+               // (5)when argument is 'xml' or 'xmlns' and namespaceURI doesn't match
                public override string Prefix {
                        set {
+                               if(IsReadOnly)
+                                       throw new XmlException ("This node is readonly.");
+
+                               XmlNamespaceManager nsmgr = ConstructNamespaceManager ();
+                               string nsuri = nsmgr.LookupNamespace (value);
+                               if(nsuri == null)
+                                       throw new XmlException ("Namespace URI not found for this prefix");
+
                                prefix = value;
                        }
                        
@@ -140,10 +168,10 @@ namespace System.Xml
                        }
                }
 
-               [MonoTODO]
+               [MonoTODO("There are no code which sets 'specified = true', so this logic is without checking.")]
                public virtual bool Specified {
                        get {
-                               throw new NotImplementedException ();
+                               return !isDefault;
                        }
                }
 
@@ -164,6 +192,14 @@ namespace System.Xml
                        }
                }
 
+               internal override string XmlLang {
+                       get { return OwnerElement.XmlLang; }
+               }
+
+               internal override XmlSpace XmlSpace {
+                       get { return OwnerElement.XmlSpace; }
+               }
+
                #endregion
 
                #region Methods
@@ -182,6 +218,11 @@ namespace System.Xml
                        return node;
                }
 
+               // Parent of XmlAttribute must be null
+               internal void SetOwnerElement (XmlElement el) {
+                       ownerElement = el;
+               }
+
                public override void WriteContentTo (XmlWriter w)
                {
                        w.WriteString (Value);