2003-10-25 Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
authorAtsushi Eno <atsushieno@gmail.com>
Sun, 26 Oct 2003 03:39:03 +0000 (03:39 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Sun, 26 Oct 2003 03:39:03 +0000 (03:39 -0000)
* DTDReader.cs, DTDValidatingReader.cs, XmlInputStream.cs,
  XmlTextReader.cs : More cleanup.
* XmlDocument.cs : Removed CheckName(). Code cleanup.
* XmlElement.cs : .ctor() now adds default attributes (if required).
* XmlAttribute.cs, XmlElement.cs, XmlEntity.cs, XmlEntityReference.cs,
  XmlNotation.cs : Now uses OwnerDocument's NameTable.

svn path=/trunk/mcs/; revision=19404

mcs/class/System.XML/System.Xml/ChangeLog
mcs/class/System.XML/System.Xml/DTDReader.cs
mcs/class/System.XML/System.Xml/DTDValidatingReader.cs
mcs/class/System.XML/System.Xml/XmlAttribute.cs
mcs/class/System.XML/System.Xml/XmlDocument.cs
mcs/class/System.XML/System.Xml/XmlElement.cs
mcs/class/System.XML/System.Xml/XmlEntity.cs
mcs/class/System.XML/System.Xml/XmlEntityReference.cs
mcs/class/System.XML/System.Xml/XmlInputStream.cs
mcs/class/System.XML/System.Xml/XmlNotation.cs
mcs/class/System.XML/System.Xml/XmlTextReader.cs

index 594631b41900efe08cd87278f283eb15e7b2988b..94a1b0bdf5c24ed0cc952c03cdb34b4cdaca950e 100644 (file)
@@ -1,3 +1,12 @@
+2003-10-25  Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
+
+       * DTDReader.cs, DTDValidatingReader.cs, XmlInputStream.cs,
+         XmlTextReader.cs : More cleanup.
+       * XmlDocument.cs : Removed CheckName(). Code cleanup.
+       * XmlElement.cs : .ctor() now adds default attributes (if required).
+       * XmlAttribute.cs, XmlElement.cs, XmlEntity.cs, XmlEntityReference.cs,
+         XmlNotation.cs : Now uses OwnerDocument's NameTable.
+
 2003-10-25  Pedro Martínez Juliá  <yoros@wanadoo.es>
 
        * XmlConvert.cs: Support for the sign in double and single. The
index bc99153da67a574c285664e8563b34dfb03b866c..966041e6203666f5d18e17d55d4f8e7962d67975 100644 (file)
@@ -928,7 +928,7 @@ namespace System.Xml
                                if (!breakup) {
                                        try {
                                                parsed = def.Datatype.ParseValue (normalized, DTD.NameTable, null);
-                                       } catch (Exception ex) { // FIXME: bad catch ;-(
+                                       } catch (Exception ex) { // FIXME: (wishlist) bad catch ;-(
                                                DTD.AddError (new XmlSchemaException ("Invalid default value for ENTITY type.",
                                                        def.LineNumber, def.LinePosition, null, def.BaseURI, ex));
                                                breakup = true;
@@ -1138,7 +1138,6 @@ namespace System.Xml
                // Does not consume the first non-whitespace character.
                private bool SkipWhitespace ()
                {
-                       //FIXME: Should not skip if whitespaceHandling == WhiteSpaceHandling.None
                        bool skipped = XmlChar.IsWhitespace (PeekChar ());
                        while (XmlChar.IsWhitespace (PeekChar ()))
                                ReadChar ();
@@ -1401,7 +1400,7 @@ namespace System.Xml
 
                        ReadChar (); // ';'
 
-                       // FIXME: how to handle such chars larger than 0xffff?
+                       // There is no way to save surrogate pairs...
                        if (value < 0xffff && !XmlConstructs.IsValid (value))
                                throw new XmlException (this as IXmlLineInfo,
                                        "Referenced character was not allowed in XML.");
@@ -1515,7 +1514,7 @@ namespace System.Xml
                        parserInputStack.Push (currentInput);
                        try {
                                currentInput = new XmlParserInput (new XmlStreamReader (url, false, DTD.Resolver, DTD.BaseURI), absPath);
-                       } catch (Exception ex) { // FIXME: Bad exception catch ;-(
+                       } catch (Exception ex) { // FIXME: (wishlist) Bad exception catch ;-(
                                int line = currentInput == null ? 0 : currentInput.LineNumber;
                                int col = currentInput == null ? 0 : currentInput.LinePosition;
                                string bu = (currentInput == null) ? String.Empty : currentInput.BaseURI;
index cedaf89ec0d50f8ccf31d4fbfee42c866cf54577..84d2298cc6f8157e32d2eae9c77fc8da233c4e5d 100644 (file)
@@ -270,7 +270,6 @@ namespace Mono.Xml
                                return false;
                }
 
-               [MonoTODO ("Handling of whitespace entities are still not enough.")]
                public override bool Read ()
                {
                        if (currentTextValue != null)
@@ -411,14 +410,12 @@ namespace Mono.Xml
                                if (currentAutomata == DTD.Invalid) {
                                        HandleError (String.Format ("Invalid start element found: {0}", reader.Name),
                                                XmlSeverityType.Error);
-                                       // FIXME: validation recovery code here.
                                        currentAutomata = previousAutomata;
                                }
                                DTDElementDeclaration decl = DTD.ElementDecls [reader.Name];
                                if (decl == null) {
                                        HandleError (String.Format ("Element {0} is not declared.", reader.Name),
                                                XmlSeverityType.Error);
-                                       // FIXME: validation recovery code here.
                                        currentAutomata = previousAutomata;
                                }
 
@@ -437,7 +434,6 @@ namespace Mono.Xml
                                                HandleError (String.Format (
                                                        "Attributes are found on element {0} while it has no attribute definitions.", currentElement),
                                                        XmlSeverityType.Error);
-                                               // FIXME: validation recovery code here.
                                        }
                                        SetupValidityIgnorantAttributes ();
                                }
@@ -463,7 +459,6 @@ namespace Mono.Xml
                                if (decl == null) {
                                        HandleError (String.Format ("Element {0} is not declared.", reader.Name),
                                                XmlSeverityType.Error);
-                                       // FIXME: validation recovery code here.
                                }
 
                                previousAutomata = currentAutomata;
@@ -472,7 +467,6 @@ namespace Mono.Xml
                                if (tmpAutomata == DTD.Invalid) {
                                        HandleError (String.Format ("Invalid end element found: {0}", reader.Name),
                                                XmlSeverityType.Error);
-                                       // FIXME: validation recovery code here.
                                        currentAutomata = previousAutomata;
                                }
 
@@ -594,7 +588,6 @@ namespace Mono.Xml
                                                } else
                                                        break;
                                        }
-                                       // FIXME: Should recursively resolve entities.
                                        switch (targetReader.NodeType) {
                                        case XmlNodeType.EntityReference:
                                                DTDEntityDeclaration edecl = DTD.EntityDecls [targetReader.Name];
@@ -626,7 +619,6 @@ namespace Mono.Xml
                                if (def == null) {
                                        HandleError (String.Format ("Attribute {0} is not declared.", reader.Name),
                                                XmlSeverityType.Error);
-                                       // FIXME: validation recovery code here.
                                } else {
                                        // check enumeration constraint
                                        if (def.EnumeratedAttributeDeclaration.Count > 0)
@@ -712,7 +704,6 @@ namespace Mono.Xml
                                                HandleError (String.Format ("Fixed attribute {0} in element {1} has invalid value {2}.",
                                                        def.Name, decl.Name, attrValue),
                                                        XmlSeverityType.Error);
-                                               // FIXME: validation recovery code here.
                                        }
                                }
                        }
@@ -724,7 +715,6 @@ namespace Mono.Xml
                                                HandleError (String.Format ("Required attribute {0} in element {1} not found .",
                                                        def.Name, decl.Name),
                                                        XmlSeverityType.Error);
-                                               // FIXME: validation recovery code here.
                                        }
                                        else if (def.DefaultValue != null) {
                                                if (this.isStandalone && !def.IsInternalSubset)
index ba60b74589eabad38c4bcc993d1d1e3e697efcf4..696bbcd4f5050e3a7c2ab274506754c5673516c6 100644 (file)
@@ -56,9 +56,9 @@ namespace System.Xml
                        else if (!XmlChar.IsName (localName))
                                throw new ArgumentException ("Invalid attribute local name.");
 
-                       this.prefix = prefix;
-                       this.localName = localName;
-                       this.namespaceURI = namespaceURI;
+                       this.prefix = doc.NameTable.Add (prefix);
+                       this.localName = doc.NameTable.Add (localName);
+                       this.namespaceURI = doc.NameTable.Add (namespaceURI);
                }
 
                #endregion
index 1256178f6e462dfdf4957d6706088f9ffd611fac..4976c140a2e48d4b9fc4a4e9622c72b2b6e85000 100644 (file)
@@ -317,7 +317,11 @@ namespace System.Xml
                {
                        if ((localName == null) || (localName == String.Empty))
                                throw new ArgumentException ("The local name for elements or attributes cannot be null or an empty string.");
-                       CheckName (localName);
+                       // FIXME: MS.NET has a weird behavior that they can Load() from XmlTextReader 
+                       // whose Namespaces = false, but their CreateElement() never allows qualified name.
+                       // I leave it as it is.
+                       if (!XmlChar.IsName (localName))
+                               throw new ArgumentException ("Invalid name.", "localName");
                        return new XmlElement (prefix != null ? prefix : String.Empty, localName, namespaceURI != null ? namespaceURI : String.Empty, this);
                }
 
@@ -363,7 +367,7 @@ namespace System.Xml
                                case XmlNodeType.Attribute: return CreateAttribute (prefix, name, namespaceURI);
                                case XmlNodeType.CDATA: return CreateCDataSection (null);
                                case XmlNodeType.Comment: return CreateComment (null);
-                               case XmlNodeType.Document: return new XmlDocument (); // TODO - test to see which constructor to use, i.e. use existing NameTable or not.
+                               case XmlNodeType.Document: return new XmlDocument ();
                                case XmlNodeType.DocumentFragment: return CreateDocumentFragment ();
                                case XmlNodeType.DocumentType: return CreateDocumentType (null, null, null, null);
                                case XmlNodeType.Element: return CreateElement (prefix, name, namespaceURI);
@@ -680,14 +684,6 @@ namespace System.Xml
                        }
                }
 
-               // Checks that Element's name is valid
-               private void CheckName (String name)
-               {
-                       // TODO: others validations?
-                       if (name.IndexOf (" ") >= 0)
-                               throw new XmlException ("The ' ' characted cannot be included in a name");
-               }
-
                // Reads XmlReader and creates Attribute Node.
                private XmlAttribute ReadAttributeNode(XmlReader reader)
                {
index dd79fa192e4ecaf68c7a6cfcfbd73d0b49fadb99..fc9fc824ce7ca754fa08493f502aac3dd9a076ca 100644 (file)
@@ -14,6 +14,7 @@ using System.Collections;
 using System.Xml.XPath;
 using System.IO;
 using System.Text;
+using Mono.Xml;
 
 namespace System.Xml
 {
@@ -37,15 +38,22 @@ namespace System.Xml
                        string namespaceURI, 
                        XmlDocument doc) : base (doc)
                {
-                       this.prefix = prefix;
-                       this.localName = localName;
-                       this.namespaceURI = namespaceURI;
+                       this.prefix = doc.NameTable.Add (prefix);
+                       this.localName = doc.NameTable.Add (localName);
+                       this.namespaceURI = doc.NameTable.Add (namespaceURI);
 
                        attributes = new XmlAttributeCollection (this);
 
-                       // TODO: Adds default attributes
                        if(doc.DocumentType != null)
                        {
+                               DTDAttListDeclaration attlist = doc.DocumentType.DTD.AttListDecls [localName];
+                               if (attlist != null) {
+                                       for (int i = 0; i < attlist.Definitions.Count; i++) {
+                                               DTDAttributeDefinition def = attlist [i];
+                                               if (def.DefaultValue != null)
+                                                       SetAttribute (def.Name, def.DefaultValue);
+                                       }
+                               }
                        }
                }
 
index b1f82dec7b9c8c3f68c3c3cc654308b07bcc041a..e0453ec672586beb36d20ceb1ae916781d7d8eda 100755 (executable)
@@ -17,7 +17,7 @@ namespace System.Xml
                                    XmlDocument doc)
                        : base (doc)
                {
-                       this.name = name;
+                       this.name = doc.NameTable.Add (name);
                        this.NDATA = NDATA;
                        this.publicId = publicId;
                        this.systemId = systemId;
index 3b822c2f139094f5bde89c7fcb66b4af5f9746b3..dd46e1942d48307704e29975585228fe8c60767c 100644 (file)
@@ -18,7 +18,7 @@ namespace System.Xml
                protected internal XmlEntityReference (string name, XmlDocument doc)\r
                        : base (doc)\r
                {\r
-                       entityName = name;\r
+                       entityName = doc.NameTable.Add (name);\r
                }\r
 \r
                // Properties\r
index d847a8794862feaa524e6d40dbf94b2394b7af5a..eaaddd8e025493480cb563b14b0eee23f43b3ccf 100644 (file)
@@ -170,11 +170,7 @@ namespace Mono.Xml.Native
                                        c = SkipWhitespace (ms);
 
                                        // version. It is optional here.
-                                       if (c != 'v') {
-                                               // FIXME: temporarily comment out here.
-//                                             if (isDocumentEntity)
-//                                                     throw new XmlException ("invalid xml declaration.");
-                                       } else {
+                                       if (c == 'v') {
                                                ms.WriteByte ((byte)'v');
                                                while (loop++ >= 0 && c >= 0) {
                                                        c = stream.ReadByte ();
index 6c92c2b925177fa4c962eec252c8c5340ebe2086..8345a7ba822ab257b59b7e7f9f272b6062de24d5 100755 (executable)
@@ -30,8 +30,8 @@ namespace System.Xml
                                      string systemId, XmlDocument doc)
                        : base (doc)
                {
-                       this.localName = localName;
-                       this.prefix = prefix;
+                       this.localName = doc.NameTable.Add (localName);
+                       this.prefix = doc.NameTable.Add (prefix);
                        this.publicId = publicId;
                        this.systemId = systemId;
                }
index 7e9fd7b13b1d43da7b6302b2e0fa86802525aba9..641f574ea94230ccc705667325d188713fb438f4 100644 (file)
@@ -1529,7 +1529,7 @@ namespace System.Xml
 
                        ReadChar (); // ';'
 
-                       // FIXME: how to handle such chars larger than 0xffff?
+                       // There is no way to save surrogate pairs...
                        if (normalization && value < 0xffff && !XmlConstructs.IsValid (value))
                                throw new XmlException (this as IXmlLineInfo,
                                        "Referenced character was not allowed in XML.");
@@ -2421,7 +2421,6 @@ namespace System.Xml
                // Does not consume the first non-whitespace character.
                private bool SkipWhitespace ()
                {
-                       //FIXME: Should not skip if whitespaceHandling == WhiteSpaceHandling.None
                        bool skipped = XmlChar.IsWhitespace (PeekChar ());
                        while (XmlChar.IsWhitespace (PeekChar ()))
                                ReadChar ();