I need to remove the "encoding" part because the XML parser on one of our
legacy systems blows-up if you include and encoding.
"Martin Honnen" <mahotrash@yahoo.de> wrote in message
news:OIAdjWj$EHA.1904@TK2MSFTNGP14.phx.gbl...
>
>
> Josh Newman wrote:
>
>> I'm using the XMLTextWriter to create an XML document. I do not want the
>> encoding attribure in the XML file.
>>
>> Instead of:
>> <?xml version="1.0" encoding="utf-8"?>
>>
>> I want:
>> <?xml version="1.0"?>
>
> Why? If you save as UTF-8 there is nothing wrong with encoding="utf-8" in
> the XML declaration.
>
>> Code extract:
>> MemoryStream ms= new MemoryStream();
>> XmlTextWriter x = new XmlTextWriter(ms, Encoding.UTF8);
>
> The XML declaration is written by the WriteStartDocument method but this
> doesn't seem to have an overload to suppress the encoding.
> I guess it should be possible to write your own class extending
> XmlTextWriter where you then override the method WriteStartDocument to
> make sure it only outputs the XML declaration with the version but with no
> encoding. I have not tested that approach though.
>
> As a sort of hack you could also try to use XmlTextWriter and then not to
> call WriteStartDocument but rather WriteProcessingInstruction with the
> proper arguments so that a processing instruction looking like an XML
> declaration is written. But that is certainly a hack and I haven't tested
> that either.
>
>
> --
>
> Martin Honnen
>
http://JavaScript.FAQTs.com/