瀏覽代碼

2003-10-13 Atsushi Enomoto <[email protected]>

	* XmlNode.cs : GetNamespaceOfPrefix() should check Attributes existence.
	  And it should throw ArgumentNullException.

svn path=/trunk/mcs/; revision=18949
Atsushi Eno 22 年之前
父節點
當前提交
a8b09dc4f6
共有 2 個文件被更改,包括 16 次插入4 次删除
  1. 5 0
      mcs/class/System.XML/System.Xml/ChangeLog
  2. 11 4
      mcs/class/System.XML/System.Xml/XmlNode.cs

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

@@ -1,3 +1,8 @@
+2003-10-13  Atsushi Enomoto <[email protected]>
+
+	* XmlNode.cs : GetNamespaceOfPrefix() should check Attributes existence.
+	  And it should throw ArgumentNullException.
+
 2003-10-13  Atsushi Enomoto <[email protected]>
 
 	* XmlAttribute.cs : Fixed InnerText that did not removed its content

+ 11 - 4
mcs/class/System.XML/System.Xml/XmlNode.cs

@@ -268,6 +268,9 @@ namespace System.Xml
 
 		public virtual string GetNamespaceOfPrefix (string prefix)
 		{
+			if (prefix == null)
+				throw new ArgumentNullException ("prefix");
+
 			XmlNode node;
 			switch (NodeType) {
 			case XmlNodeType.Attribute:
@@ -286,10 +289,14 @@ namespace System.Xml
 			while (node != null) {
 				if (node.Prefix == prefix)
 					return node.NamespaceURI;
-				foreach (XmlAttribute attr in node.Attributes) {
-					if (prefix == attr.LocalName && attr.Prefix == "xmlns"
-						|| attr.Name == "xmlns" && prefix == String.Empty)
-						return attr.Value;
+				if (node.Attributes != null) {
+					int count = node.Attributes.Count;
+					for (int i = 0; i < count; i++) {
+						XmlAttribute attr = node.Attributes [i];
+						if (prefix == attr.LocalName && attr.Prefix == "xmlns"
+							|| attr.Name == "xmlns" && prefix == String.Empty)
+							return attr.Value;
+					}
 				}
 				node = node.ParentNode;
 			}