Do you understand you own code? What do you want to return from this method? Currently your code means following:
Read XML file until "Keyword" element will not be found. After "Keyword" element will be found take value of it's "name" attribute and return it wrapped into one element array.
As others have mentioned there can be case when XML document will not have element. In that case you will exit your loop with no value returned. You should decide what to do in that case. You can return some special value like "null" or empty array. Or if you are sure that at least one "Keyword" element should exist in specified XML document then you can throw some Exception from the end of method to indicate that some pre-condition was violated.
I think you've tried to write method with different behavior. I believe you've meant following:
Read XML file and collect values of "name" attribute from all "Keyword" elements and return collected values as string array.
That will be more meaningful and in that case you will always have some result even when XML file will not contain any "Keyword" element. To achieve such behavior you should move list to array conversion and return statement to the end of method. You will have code like this:
public static String[] readXML(String filename)
{
using(XmlReader xmlReader = XmlReader.Create(@filename))
{
List<String> names = new List<string>();
while(xmlReader.Read())
{
//Keep reading
if(xmlReader.Name.Equals("Keyword") && (xmlReader.NodeType == XmlNodeType.Element))
{
// get attribute from the Xml element here
string keywords = xmlReader.GetAttribute("name");
names.Add(keywords);
}
}
String[] keywordsArray = names.ToArray();
return keywordsArray;
}
}
Please note that I've also wrapped usage of created XmlReader in "using" block to ensure that it will be disposed before we will leave the method.