Is there any way to output the contents of an XDocument without the BOM? When reading the output with Flash, it causes errors.
相关问题
- Illegal to have multiple roots (start tag in epilo
- Generic Generics in Managed C++
- How to Debug/Register a Permanent WMI Event Which
- 'System.Threading.ThreadAbortException' in
- Bulk update SQL Server C#
If you're writing the XML with an XmlWriter, you can set the Encoding to one that has been initialized to leave out the BOM.
EG: System.Text.UTF8Encoding's constructor takes a boolean to specify whether you want the BOM, so:
Would create an XmlWriter with UTF-8 encoding and without the Byte Order Mark.
You could probably use System.Text.Encoding.Convert() on the output; Just as something to try, not something I have tested.
Convert it to a string, then remove the mark yourself.
Slight mod to Chris Wenham's answer.
You can't modify the encoding once the XmlWriter is created, but you can set it using the XmlWriterSettings when creating the XmlWriter
I couldn't add a comment above, but if anyone uses Chris Wenham's suggestion, remember to Dispose of the writer! I spent some time wondering why my output was truncated, and that was the reason.
Suggest a
using(XmlWriter...) {...}
change to Chris' suggestionKind of a combination of postings, maybe something like this: