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
+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.
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));
node.AppendChild (ChildNodes [i].CloneNode (deep));
}
+ if (IsReadOnly)
+ node.SetReadOnly ();
return node;
}
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)
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);
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) { }
set {
OwnerDocument.onNodeChanging (this, this.ParentNode);
- if (IsReadOnly)
- throw new ArgumentException ("Node is read-only.");
-
data = value;
OwnerDocument.onNodeChanged (this, this.ParentNode);
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,
node.AppendChild (ChildNodes [i].CloneNode (true));
}
+ if (IsReadOnly)
+ node.SetReadOnly ();
return node;
}
if(n == null) break;
InsertBefore (n, null, false, false);
} while (true);
+
+ SetReadOnly (this);
}\r
#endregion
}
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
// 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
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
StringBuilder tmpBuilder;
XmlLinkedNode lastLinkedChild;
XmlNodeListChildren childNodes;
+ bool isReadOnly;
#endregion
}
public virtual bool IsReadOnly {
- get { return false; }
+ get { return isReadOnly; }
}
[System.Runtime.CompilerServices.IndexerName("Item")]
{
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);
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];
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)
{
// 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) {}
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;
}