2004-04-24 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Sat, 24 Apr 2004 14:23:56 +0000 (14:23 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Sat, 24 Apr 2004 14:23:56 +0000 (14:23 -0000)
W3C DOM compliant read-only check support (buggy part in MS.NET).
* XmlAttribute.cs,
  XmlCDataSection.cs,
  XmlCharacterData.cs,
  XmlDocument.cs,
  XmlElement.cs,
  XmlNode.cs,
  XmlSignificantWhitespace.cs,
  XmlText.cs
  : CloneNode() - set read-only when copied node is read-only.
    Check IsReadOnly on attempt to modify value.
* XmlEntity.cs,
  XmlEntityReference.cs : Set descendant nodes read-only.
* XmlAttributeCollection.cs,
  XmlNode.cs
  : Fixed incompatible exception type.
* XmlEntityReference.cs : CloneNode() should not pass an empty string
  as its name.
* XmlEntityReference.cs,
  XmlProcessingInstruction.cs : Check XML name validity.
* XmlText.cs : CloneNode() does not have to check children.

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

12 files changed:
mcs/class/System.XML/System.Xml/ChangeLog
mcs/class/System.XML/System.Xml/XmlAttribute.cs
mcs/class/System.XML/System.Xml/XmlAttributeCollection.cs
mcs/class/System.XML/System.Xml/XmlCDataSection.cs
mcs/class/System.XML/System.Xml/XmlCharacterData.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/XmlNode.cs
mcs/class/System.XML/System.Xml/XmlSignificantWhitespace.cs
mcs/class/System.XML/System.Xml/XmlText.cs

index 32979d462d6112a4d48d8e9f15f3de92bc31beb7..5f2805256d6e6857b035e18c379de18df9cdd8fb 100644 (file)
@@ -1,3 +1,27 @@
+2004-04-24  Atsushi Enomoto <atsushi@ximian.com>
+
+       W3C DOM compliant read-only check support (buggy part in MS.NET).
+       * XmlAttribute.cs,
+         XmlCDataSection.cs,
+         XmlCharacterData.cs,
+         XmlDocument.cs,
+         XmlElement.cs,
+         XmlNode.cs,
+         XmlSignificantWhitespace.cs,
+         XmlText.cs
+         : CloneNode() - set read-only when copied node is read-only.
+           Check IsReadOnly on attempt to modify value.
+       * XmlEntity.cs,
+         XmlEntityReference.cs : Set descendant nodes read-only.
+       * XmlAttributeCollection.cs,
+         XmlNode.cs
+         : Fixed incompatible exception type.
+       * XmlEntityReference.cs : CloneNode() should not pass an empty string
+         as its name.
+       * XmlEntityReference.cs,
+         XmlProcessingInstruction.cs : Check XML name validity.
+       * XmlText.cs : CloneNode() does not have to check children.
+
 2004-04-24  Atsushi Enomoto <atsushi@ximian.com>
 
        * XmlDeclaration.cs : More strict check on InnerText and Value.
index 7b008b0a7ecd0545c525c405e09b6527f14c1d87..01d981fc8c077b7d4525d1be07e249202009c7ba 100644 (file)
@@ -211,6 +211,8 @@ namespace System.Xml
                        get { return BuildChildValue (ChildNodes); }
 
                        set {
+                               if (this.IsReadOnly)
+                                       throw new ArgumentException ("Attempt to modify a read-only node.");
                                XmlNode firstChild = FirstChild;
                                if (firstChild == null)
                                        AppendChild (OwnerDocument.CreateTextNode (value));
@@ -245,6 +247,8 @@ namespace System.Xml
                                        node.AppendChild (ChildNodes [i].CloneNode (deep));
                        }
 
+                       if (IsReadOnly)
+                               node.SetReadOnly ();
                        return node;
                }
 
index 1ebacd38b515b7bd5efa08a7381b472f5941641e..1cf04273c800237f9660bdf86cf18d32f059680b 100644 (file)
@@ -129,6 +129,8 @@ namespace System.Xml
 
                public virtual XmlAttribute Remove (XmlAttribute node) 
                {
+                       if (IsReadOnly)
+                               throw new ArgumentException ("This attribute collection is read-only.");
                        if (node == null)
                                throw new ArgumentException ("Specified node is null.");
                        if (node.OwnerDocument != ownerDocument)
@@ -186,11 +188,11 @@ namespace System.Xml
                public override XmlNode SetNamedItem (XmlNode node)
                {
                        if(IsReadOnly)
-                               throw new XmlException ("this AttributeCollection is read only.");
+                               throw new ArgumentException ("this AttributeCollection is read only.");
 
                        XmlAttribute attr = node as XmlAttribute;
                        if (attr.OwnerElement != null)
-                               throw new InvalidOperationException ("This attribute is already set to another element.");
+                               throw new ArgumentException ("This attribute is already set to another element.");
 
                        ownerElement.OwnerDocument.onNodeInserting (node, ownerElement);
 
index fae8571888385f54d9086ff113fa65efe24877e1..06af2eae327f4c34c1b89a837124943d99296a27 100644 (file)
@@ -39,7 +39,10 @@ namespace System.Xml
 
                public override XmlNode CloneNode (bool deep)
                {
-                       return new XmlCDataSection (Data, OwnerDocument); // CDATA nodes have no children.
+                       XmlNode n = new XmlCDataSection (Data, OwnerDocument); // CDATA nodes have no children.
+                       if (IsReadOnly)
+                               n.SetReadOnly ();
+                       return n;
                }
 
                public override void WriteContentTo (XmlWriter w) {     }
index 6872be87823ca1ab4d2c200a31cd8e2f18f2aa7c..947206471f27a78aebda79bb0384808006478cbd 100644 (file)
@@ -38,9 +38,6 @@ namespace System.Xml
                        set {
                                OwnerDocument.onNodeChanging (this, this.ParentNode);
 
-                               if (IsReadOnly)
-                                       throw new ArgumentException ("Node is read-only.");
-
                                data = value;
 
                                OwnerDocument.onNodeChanged (this, this.ParentNode);
index 694e8363a4b044aa55c29fc3bdef4797e4c5b079..5064834b3f16e3ff0e0f6cacccee0262c11d4626 100644 (file)
@@ -634,6 +634,8 @@ namespace System.Xml
 
                internal void onNodeChanging(XmlNode node, XmlNode Parent)
                {
+                       if (node.IsReadOnly)
+                               throw new ArgumentException ("Node is read-only.");
                        if (NodeChanging != null)
                                NodeChanging (node, new XmlNodeChangedEventArgs
                                        (XmlNodeChangedAction.Change,
index 82dfc7b9a5c32ff3d6cfd25ef97b0a1059afc456..340b79d5bd5c4b4cf08c09217a6a2cad8c032738 100644 (file)
@@ -215,6 +215,8 @@ namespace System.Xml
                                        node.AppendChild (ChildNodes [i].CloneNode (true));
                        }
 
+                       if (IsReadOnly)
+                               node.SetReadOnly ();
                        return node;
                }
 
index 6d8bf37b242e2ba5b2bd5c38e57a23b739239f62..3a47f9e2f26d4593d6f15ee679cacb7d940da57f 100755 (executable)
@@ -147,6 +147,8 @@ namespace System.Xml
                                if(n == null) break;
                                InsertBefore (n, null, false, false);
                        } while (true);
+
+                       SetReadOnly (this);
                }\r
                #endregion
        }
index a118a472b60f57eaf7bef1b2ebdab15de3668cc4..16d1429b7ffbb9c30f21ffbdf27900d9f1e481f0 100644 (file)
@@ -21,6 +21,8 @@ namespace System.Xml
                protected internal XmlEntityReference (string name, XmlDocument doc)\r
                        : base (doc)\r
                {\r
+                       // LAMESPEC: MS CreateNode() allows null node name.\r
+                       XmlConvert.VerifyName (name);\r
                        entityName = doc.NameTable.Add (name);\r
                }\r
 \r
@@ -66,7 +68,7 @@ namespace System.Xml
                        // API docs: "The replacement text is not included." XmlNode.CloneNode\r
                        // "The replacement text is set when node is inserted." XmlEntityReference.CloneNode\r
                        //\r
-                       return new XmlEntityReference ("", OwnerDocument);\r
+                       return new XmlEntityReference (Name, OwnerDocument);\r
                }\r
 \r
                public override void WriteContentTo (XmlWriter w)\r
@@ -99,6 +101,7 @@ namespace System.Xml
                                for (int i = 0; i < ent.ChildNodes.Count; i++)\r
                                        InsertBefore (ent.ChildNodes [i].CloneNode (true), null, false, true);\r
                        }\r
+                       SetReadOnly (this);\r
                }\r
        }\r
 }\r
index 2de50dac78d3d638b1bb662c6a0d3ce3a836c2da..ffbfc839b9c994a86ccf0b1a281f2fbc986680db 100644 (file)
@@ -27,6 +27,7 @@ namespace System.Xml
                StringBuilder tmpBuilder;
                XmlLinkedNode lastLinkedChild;
                XmlNodeListChildren childNodes;
+               bool isReadOnly;
 
                #endregion
 
@@ -120,7 +121,7 @@ namespace System.Xml
                }
 
                public virtual bool IsReadOnly {
-                       get { return false; }
+                       get { return isReadOnly; }
                }
 
                [System.Runtime.CompilerServices.IndexerName("Item")]
@@ -610,7 +611,7 @@ namespace System.Xml
                {
                        XmlDocument ownerDoc = (NodeType == XmlNodeType.Document) ? (XmlDocument)this : OwnerDocument;
                        if(oldChild.ParentNode != this)
-                               throw new XmlException ("The node to be removed is not a child of this node.");
+                               throw new ArgumentException ("The node to be removed is not a child of this node.");
 
                        if (checkNodeType)
                                ownerDoc.onNodeRemoving (oldChild, oldChild.ParentNode);
@@ -652,10 +653,10 @@ namespace System.Xml
                public virtual XmlNode ReplaceChild (XmlNode newChild, XmlNode oldChild)
                {
                        if(oldChild.ParentNode != this)
-                               throw new InvalidOperationException ("The node to be removed is not a child of this node.");
+                               throw new ArgumentException ("The node to be removed is not a child of this node.");
                        
                        if (newChild == this || IsAncestor (newChild))
-                               throw new ArgumentException("Cannot insert a node or any ancestor of that node as a child of itself.");
+                               throw new InvalidOperationException("Cannot insert a node or any ancestor of that node as a child of itself.");
                        
                        for (int i = 0; i < ChildNodes.Count; i++) {
                                XmlNode n = ChildNodes [i];
@@ -730,6 +731,21 @@ namespace System.Xml
                                return null;
                        return ((XmlDocumentNavigator) iter.Current).Node;
                }
+\r
+               internal static void SetReadOnly (XmlNode n)\r
+               {\r
+                       if (n.Attributes != null)\r
+                               for (int i = 0; i < n.Attributes.Count; i++)\r
+                                       SetReadOnly (n.Attributes [i]);\r
+                       for (int i = 0; i < n.ChildNodes.Count; i++)\r
+                               SetReadOnly (n.ChildNodes [i]);\r
+                       n.isReadOnly = true;\r
+               }\r
+\r
+               internal void SetReadOnly ()\r
+               {\r
+                       isReadOnly = true;\r
+               }\r
 
                public virtual bool Supports (string feature, string version)
                {
index 140c9a9e33932038587581ed2dc021b9f2d95a1e..e75d9e1be9752009e4f24c76ffd66cab4a96f068 100644 (file)
@@ -51,7 +51,10 @@ namespace System.Xml
                // Methods
                public override XmlNode CloneNode (bool deep)
                {
-                       return new XmlSignificantWhitespace (Data, OwnerDocument);
+                       XmlNode n = new XmlSignificantWhitespace (Data, OwnerDocument);
+                       if (IsReadOnly)
+                               n.SetReadOnly ();
+                       return n;
                }
 
                public override void WriteContentTo (XmlWriter w) {}
index bd5af462c1d4fa3d1cbe7f555e2f107af22f38ac..ac7b608a08d30e4796f2f886b9dd411da2d493ce 100644 (file)
@@ -55,10 +55,8 @@ namespace System.Xml
                public override XmlNode CloneNode (bool deep)
                {
                        XmlText newText = OwnerDocument.CreateTextNode(Data);
-                       if(deep) {
-                               for (int i = 0; i < ChildNodes.Count; i++)
-                                       newText.AppendChild (ChildNodes [i].CloneNode (deep));
-                       }
+                       if (IsReadOnly)
+                               newText.SetReadOnly ();
                        return newText;
                }