为什么运行这段代码...
XmlDocument doc = new XmlDocument();
string xml = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<BaaBaa>
<BlackSheep HaveYouAny=""Wool"" />
</BaaBaa>";
doc.LoadXml(xml);
XmlNodeList nodes = doc.SelectNodes("//BaaBaa");
foreach (XmlElement element in nodes)
{
Console.WriteLine(element.InnerXml);
XmlAttributeCollection attributes = element.Attributes;
Console.WriteLine(attributes.Count);
}
在命令提示符下产生以下输出?
<BlackSheep HaveYouAny="Wool" />
0
也就是说,不应该attributes.Count
返回 1 吗?