Writing namespace to an XML stream
Date: 02/11/09
(C Sharp) Keywords: html, xml
I'm trying to write XHTML to an XmlWriter. I'm having trouble generating the standard line:
http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
With "writer" as my XmlWriter I have
writer.WriteStartElement("html");
writer.WriteAttributeString("xmlns", "http://www.w3.org/1999/xhtml");
writer.WriteAttributeString("lang", "en");
writer.WriteAttributeString("xml:lang", "en");
but writer.WriteAttributeString("xmlns", "http://www.w3.org/1999/xhtml") generates an XmlException: "The prefix '' cannot be redefined from '' to 'http://www.w3.org/1999/xhtml' within the same start element tag."
What am I missing? How do I get that namespace defined?
TIA.
Source: http://community.livejournal.com/csharp/101629.html