Problem with XDocument and specification (byte byte mark)

Is there a way to output the contents of an XDocument without a specification? When reading output using Flash, it causes errors.

+5
source share
7 answers

If you write XML using XmlWriter, you can set the encoding to the one that was initialized to exclude the specification.

EG: the constructor of System.Text.UTF8Encoding takes a boolean value to indicate whether you want a specification, therefore:

XmlWriter writer = XmlWriter.Create("foo.xml");
writer.Settings.Encoding = new System.Text.UTF8Encoding(false);
myXDocument.WriteTo(writer);

Would create an XmlWriter with UTF-8 encoding and unsigned byte order.

+9
source

Minor mod for Chris Wenham's answer.

XmlWriter, XmlWriterSettings XmlWriter

XmlWriterSettings settings = new XmlWriterSettings();
settings.Encoding = new System.Text.UTF8Encoding(false); 

XmlWriter writer = XmlWriter.Create("foo.xml", settings); 
myXDocument.WriteTo(writer); 
+5

, - , ! , , , .

using(XmlWriter...) {...}

+3

, , - :


MemoryStream ms = new MemoryStream();
StreamWriter writer = new StreamWriter(ms, new UTF8Encoding(false));
xmlDocument.Save(writer);
+2

, .

, Flash UTF-16BE UTF-16LE, , , Flash: XDocument XML-, UTF16, Macromedia , Flash XML- UTF16.

, , , , , . , , , - .

+1

, System.Text.Encoding.Convert() ; , - , , .

0
source

Convert it to a string, then uncheck it yourself.

0
source

All Articles