I have an XElement object for the following xml.
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<body>
<div>Hello world</div>
</body>
</html>
I want to add xml:lang="en" to tag. So it become
<html xml:lang="en" lang="en" xmlns="http://www.w3.org/1999/xhtml">
I tried the following code.
XAttribute xmlLang = new XAttribute("xml:lang","en");
But I got the following error:
The ':' character, hexadecimal value 0x3A, cannot be included in a name.
Thanks for your help.
You need to pass an XName instance that consists of the namespace (http://www.w3.org/1999/xhtml) and the local name (lang) to the XAttribute constructor.
XAttribute xmlLang = new XAttribute(XNamespace.Xml + "lang", "en");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With