2003-10-25 Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
[mono.git] / mcs / class / System.XML / System.Xml / XmlAttribute.cs
index 52afc6e1fff792fb08fe73bfa75073dde6e68a04..ba60b74589eabad38c4bcc993d1d1e3e697efcf4 100644 (file)
@@ -33,7 +33,7 @@ namespace System.Xml
                protected internal XmlAttribute (
                        string prefix, 
                        string localName, 
-                       string namespaceURI, 
+                       string namespaceURI,
                        XmlDocument doc) : base (doc)
                {
                        if (prefix == null)
@@ -51,11 +51,10 @@ namespace System.Xml
 
                        // There are no means to identify the DOM is namespace-
                        // aware or not, so we can only check Name validity.
-                       Exception ex;
-                       if (prefix != "" && !XmlConstructs.IsValidName (prefix, out ex))
-                               throw ex;
-                       else if (!XmlConstructs.IsValidName (localName, out ex))
-                               throw ex;
+                       if (prefix != "" && !XmlChar.IsName (prefix))
+                               throw new ArgumentException ("Invalid attribute prefix.");
+                       else if (!XmlChar.IsName (localName))
+                               throw new ArgumentException ("Invalid attribute local name.");
 
                        this.prefix = prefix;
                        this.localName = localName;
@@ -74,28 +73,14 @@ namespace System.Xml
 
                public override string InnerText {
                        get {
-                               StringBuilder builder = new StringBuilder ();
-                               AppendChildValues (this, builder);
-                               return builder.ToString ();
-                        }
+                               return base.InnerText;
+                       }
 
                        set {
                                Value = value;
                        }
                }
 
-               private void AppendChildValues (XmlNode parent, StringBuilder builder)
-               {
-                       XmlNode node = parent.FirstChild;
-                       
-                       while (node != null) {
-                               builder.Append (node.Value);
-                               AppendChildValues (node, builder);
-                               node = node.NextSibling;
-                        }
-                }
-               
-               [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.
@@ -105,8 +90,12 @@ namespace System.Xml
                        set {
                                RemoveAll ();
                                XmlNamespaceManager nsmgr = ConstructNamespaceManager ();
-                               XmlParserContext ctx = new XmlParserContext (OwnerDocument.NameTable, nsmgr, XmlLang, this.XmlSpace);
+                               XmlParserContext ctx = new XmlParserContext (OwnerDocument.NameTable, nsmgr,
+                                       OwnerDocument.DocumentType != null ? OwnerDocument.DocumentType.DTD : null,
+                                       BaseURI, XmlLang, XmlSpace, null);
                                XmlTextReader xtr = new XmlTextReader (value, XmlNodeType.Attribute, ctx);
+                               xtr.XmlResolver = OwnerDocument.Resolver;
+                               xtr.Read ();
                                OwnerDocument.ReadAttributeNodeValue (xtr, this);
                        }
                }
@@ -160,21 +149,18 @@ namespace System.Xml
                        }
                }
 
-               [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.");
-                               Exception ex;
-                               if (!XmlConstructs.IsValidNCName (value, out ex))
-                                       throw ex;
+                               if (!XmlChar.IsNCName (value))
+                                       throw new ArgumentException ("Specified name is not a valid NCName: " + value);
 
                                prefix = value;
                        }
@@ -184,7 +170,6 @@ namespace System.Xml
                        }
                }
 
-               [MonoTODO("There are no code which sets 'specified = true', so this logic is without checking.")]
                public virtual bool Specified {
                        get {
                                return !isDefault;
@@ -203,6 +188,10 @@ namespace System.Xml
                                XmlNode firstChild = FirstChild;
                                if (firstChild == null)
                                        AppendChild (OwnerDocument.CreateTextNode (value));
+                               else if (FirstChild.NextSibling != null) {
+                                       this.RemoveAll ();
+                                       AppendChild (OwnerDocument.CreateTextNode (value));
+                               }
                                else
                                        firstChild.Value = value;
                        }
@@ -232,6 +221,11 @@ namespace System.Xml
                        return node;
                }
 
+               internal void SetDefault ()
+               {
+                       isDefault = true;
+               }
+
                // Parent of XmlAttribute must be null
                internal void SetOwnerElement (XmlElement el) {
                        ownerElement = el;