This method:
public static string[] getKeywords(string filename)
{
string[] keywords = XElement.Load(filename).Elements("Keyword").Attributes("name").Select(n => n.Value).ToArray
return keywords;
}
Will not read the xml file. I have even tested every place it was called and it led back to getKeywords. I even tested it by
string[] test = getKeywords("APIs\\cmake.xml");
textbox.Text = test[0];
And I get an ArrayIndexOutOfBounds Exception. The xml file is accessable by this method. Just that it does not read the attribute. Here is a sample of the xml file:
<Keywords>
...
<Keyword name ="if" />
<Keyword name ="else" />
...
</Keywords>
What is wrong?
EDIT: The
Elements("Keyword")call returns the an enumerable containing the all of theKeywordelements that are directly within the document root. Since there aren’t any (the document root contains a singleKeywords(plural) element), you’re not getting any values.You need to get all of the
Keywordelements in the document, like this:Alternatively, you can explicitly get all of the
Keywordelements within theKeywordselement, like this: (This will not getKeywordelements that are inside of other elements)