这种方法:方法不读XML属性
public static string[] getKeywords(string filename)
{
string[] keywords = XElement.Load(filename).Elements("Keyword").Attributes("name").Select(n => n.Value).ToArray
return keywords;
}
不会读取XML文件。我甚至测试了它所称的每一个地方,并将其带回getKeywords。我甚至通过测试它
string[] test = getKeywords("APIs\\cmake.xml");
textbox.Text = test[0];
而且我得到一个ArrayIndexOutOfBounds异常。这个方法可以访问xml文件。只是它不读取属性。以下是xml文件的示例:
<Keywords>
...
<Keyword name ="if" />
<Keyword name ="else" />
...
</Keywords>
出了什么问题?
对不起,那是我的错字 – 2010-01-13 00:33:29
这段代码返回'{“如果”,“否则”}'我;这是不对的? – 2010-01-13 00:46:51