Domanda

Se si utilizza una XmlWriter per il rendering HTML. Come posso ottenere un XmlWriter per emettere un tag corretto che assomiglia a questo?

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

Ecco quello che ho finora

    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");
    ...

L'ultima riga si blocca

È stato utile?

Soluzione

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();
        }
    }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top