The ‘:’ character, hexadecimal value 0x3A, cannot be included in a name
To use namespaces, LINQ to XML will makes it by simple:
XNamespace ab = "http://whatever-the-url-is"; XElement tempElement = doc.Descendants(ab + "test").FirstOrDefault();
Search for an xmlns:ab=… section in the document to find that which namespace URI “ab” will refers to.
Here is the solution:
var ab = "http://whatever-the-url-is";
here, ab was said to be a string. It caused the error reported by OP. In behalf of using the VAR keyword, here used the actual data type XNamespace.
XNamespace ab = "http://whatever-the-url-is";
It’s for XML Namespace. If an element type name or attribute name contains a colon, then the mapping treats the part of the name before the colon as a prefix (of Namespace), and the part of the name after the colon as the local name.
If Abc is your namespace your should use this code
XNamespace aw = "Abc"; XElement root = new XElement(aw + "Xyz", string.Empty);