How do you get an XmlWriter to write an HTML tag with xmlns and xml: lang?

I am using XmlWriter to render HTML. How can I get XmlWriter to emit the correct tag that looks like this?

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

that's what i still have

    var xml = XmlWriter.Create(HtmlFileName, new XmlWriterSettings { Indent = true, OmitXmlDeclaration = true});
    xml.WriteDocType("html", "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", null);
    xml.WriteStartElement("html");            
    xml.WriteAttributeString("xmlns", "http://www.w3.org/1999/xhtml");
    ...

Last line crash

+3
source share
1 answer
class Program
{
    static void Main(string[] args)
    {
        using (var xml = XmlWriter.Create(Console.Out, new XmlWriterSettings { Indent = true, OmitXmlDeclaration = true }))
        {
            xml.WriteDocType("html", "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", null);
            xml.WriteStartElement("html", "http://www.w3.org/1999/xhtml");
            xml.WriteAttributeString("xml", "lang", "", "en");
            xml.WriteEndElement();
        }
    }
}
+7
source

Source: https://habr.com/ru/post/1720591/


All Articles