How to add xml:lang="en" to <html> tag
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");
精彩评论