2009-10-20 57 views
3

我正在使用XmlWriter來呈現HTML。我怎樣才能讓XmlWriter發出一個看起來像這樣的適當標籤?如何讓XmlWriter使用xmlns和xml:lang編寫HTML標記?

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

這裏是我迄今爲止

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

最後一行崩潰

回答

7
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(); 
     } 
    } 
} 
+0

這做到了謝謝! – 2009-10-20 18:50:27