XmlException for the '/' character hex value 0x2F cannot be included in a name

Mohit Deshpande picture Mohit Deshpande · Jan 12, 2010 · Viewed 7k times · Source

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

Answer

Marc Gravell picture Marc Gravell · Jan 12, 2010

new XElement(filename) means create an element with the name from filename - do you mean XElement.Load(filename) ??