How can I solve the exception generated?
public static string[] getKeywords(string filename)
{
var xmlFile = new XElement(filename);
string[] keywords = xmlFile.Elements("Keyword")
.Attributes("name")
.Select(n => n.Value).ToArray();
return keywords;
}
This generates this exception:
System.Xml.XmlException was unhandled Message=The '/' character, hexadecimal value 0x2F, cannot be included in a name. Source=System.Xml
new XElement(filename)
意味着使用filename
的名称创建一个元素-您的意思是XElement.Load(filename)
?
You were trying to load the file name as XML hence it was throwing an exception. This is what you wanted;
public static string[] getKeywords(string filename)
{
var xmlFile = XElement.Load(filename);
string[] keywords = xmlFile.Elements("Keyword").Attributes("name").Select(n => n.Value).ToArray();
return keywords;
}
Using the XElement.Load() method.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.