Search code examples
c#xmlexception

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


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


Solution

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