ソースを参照

2004-03-24 Atsushi Enomoto <[email protected]>

	* XmlAttributeCollection.cs : Remove() should throw an exception when
	  target attribute is not included in the collection.
	* XmlDocument.cs : ImportNode() should reject null node.
	* XmlNode.cs : Fixed type of exception for invalid insertion.
	  It should throw an exception not only when the owner document of the
	  reference element is different but its parent element is different.
	  Some error message improvement.

svn path=/trunk/mcs/; revision=24509
Atsushi Eno 22 年 前
コミット
3aee5d6284

+ 10 - 0
mcs/class/System.XML/System.Xml/ChangeLog

@@ -1,3 +1,13 @@
+2004-03-24  Atsushi Enomoto <[email protected]>
+
+	* XmlAttributeCollection.cs : Remove() should throw an exception when
+	  target attribute is not included in the collection.
+	* XmlDocument.cs : ImportNode() should reject null node.
+	* XmlNode.cs : Fixed type of exception for invalid insertion.
+	  It should throw an exception not only when the owner document of the
+	  reference element is different but its parent element is different.
+	  Some error message improvement.
+
 2004-03-21  Atsushi Enomoto <[email protected]>
 
 	* XmlReader.cs : ReadInnerXml() incorrectly tried to get output xml.

+ 2 - 0
mcs/class/System.XML/System.Xml/XmlAttributeCollection.cs

@@ -133,6 +133,8 @@ namespace System.Xml
 				throw new ArgumentException ("Specified node is null.");
 			if (node.OwnerDocument != ownerDocument)
 				throw new ArgumentException ("Specified node is in a different document.");
+			if (node.OwnerElement != this.ownerElement)
+				throw new ArgumentException ("The specified attribute is not contained in the element.");
 
 			XmlAttribute retAttr = null;
 			for (int i = 0; i < Nodes.Count; i++) {

+ 3 - 0
mcs/class/System.XML/System.Xml/XmlDocument.cs

@@ -487,6 +487,9 @@ namespace System.Xml
 
 		public virtual XmlNode ImportNode (XmlNode node, bool deep)
 		{
+			if (node == null)
+				throw new NullReferenceException ("Null node cannot be imported.");
+
 			switch (node.NodeType) {
 			case XmlNodeType.Attribute:
 				XmlAttribute srcAtt = node as XmlAttribute;

+ 12 - 10
mcs/class/System.XML/System.Xml/XmlNode.cs

@@ -457,13 +457,13 @@ namespace System.Xml
 
 		private void CheckNodeInsertion (XmlNode newChild, XmlNode refChild)
 		{
-			XmlDocument ownerDoc = (NodeType == XmlNodeType.Document) ? (XmlDocument)this : OwnerDocument;
+			XmlDocument ownerDoc = (NodeType == XmlNodeType.Document) ? (XmlDocument) this : OwnerDocument;
 
 			if (NodeType != XmlNodeType.Element &&
 			    NodeType != XmlNodeType.Attribute &&
 			    NodeType != XmlNodeType.Document &&
 			    NodeType != XmlNodeType.DocumentFragment)
-				throw new InvalidOperationException (String.Format ("current node {0} is not allowed to have any children.", NodeType));
+				throw new InvalidOperationException (String.Format ("Node cannot be appended to current node " + NodeType + "."));
 
 			switch (NodeType) {
 			case XmlNodeType.Attribute:
@@ -472,7 +472,7 @@ namespace System.Xml
 				case XmlNodeType.EntityReference:
 					break;
 				default:
-					throw new ArgumentException (String.Format (
+					throw new InvalidOperationException (String.Format (
 						"Cannot insert specified type of node {0} as a child of this node {0}.", 
 						newChild.NodeType, NodeType));
 				}
@@ -485,19 +485,21 @@ namespace System.Xml
 				case XmlNodeType.Entity:
 				case XmlNodeType.Notation:
 				case XmlNodeType.XmlDeclaration:
-					throw new ArgumentException ("Cannot insert specified type of node as a child of this node.");
+					throw new InvalidOperationException ("Cannot insert specified type of node as a child of this node.");
 				}
 				break;
 			}
 
 			if (IsReadOnly)
-				throw new ArgumentException ("The specified node is readonly.");
+				throw new InvalidOperationException ("The node is readonly.");
 
 			if (newChild.OwnerDocument != ownerDoc)
 				throw new ArgumentException ("Can't append a node created by another document.");
 
-			if (refChild != null && newChild.OwnerDocument != refChild.OwnerDocument)
-					throw new ArgumentException ("argument nodes are on the different documents.");
+			if (refChild != null) {
+				if (refChild.ParentNode != this)
+					throw new ArgumentException ("The reference node is not a child of this node.");
+			}
 
 			if(this == ownerDoc && ownerDoc.DocumentElement != null && (newChild is XmlElement))
 				throw new XmlException ("multiple document element not allowed.");
@@ -597,7 +599,7 @@ namespace System.Xml
 				NodeType != XmlNodeType.Element && 
 				NodeType != XmlNodeType.Document && 
 				NodeType != XmlNodeType.DocumentFragment)
-				throw new ArgumentException (String.Format ("This {0} node cannot remove child.", NodeType));
+				throw new ArgumentException (String.Format ("This {0} node cannot remove its child.", NodeType));
 
 			if (IsReadOnly)
 				throw new ArgumentException (String.Format ("This {0} node is read only.", NodeType));
@@ -607,7 +609,7 @@ namespace System.Xml
 		{
 			XmlDocument ownerDoc = (NodeType == XmlNodeType.Document) ? (XmlDocument)this : OwnerDocument;
 			if(oldChild.ParentNode != this)
-				throw new XmlException ("specified child is not child of this node.");
+				throw new XmlException ("The node to be removed is not a child of this node.");
 
 			if (checkNodeType)
 				ownerDoc.onNodeRemoving (oldChild, oldChild.ParentNode);
@@ -649,7 +651,7 @@ namespace System.Xml
 		public virtual XmlNode ReplaceChild (XmlNode newChild, XmlNode oldChild)
 		{
 			if(oldChild.ParentNode != this)
-				throw new InvalidOperationException ("oldChild is not a child of this node.");
+				throw new InvalidOperationException ("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.");