标签 xml 下的文章

C#中以UTF-8编码无BOM头保存XML

c#中直接以XmlDocument.Save()接口以UTF-8编码保存的XML文件是包含BOM头的,怎么以无BOM头UTF-8编码保存XML呢?

参考代码如下:

/// <summary>
/// 以UTF-8无BOM编码保存xml至文件。
/// </summary>
/// <param name="savePath">保存至路径</param>
/// <param name="xml"></param>
public static void SaveXmlWithUTF8NotBOM(string savePath, XmlDocument xml)
{
    StreamWriter sw = new StreamWriter(savePath, false, new UTF8Encoding(false));
    xml.Save(sw);
    sw.WriteLine();
    sw.Close();
}

深入分析AS3 TypeError: Error #1088: The markup in the document following the root element must be well-formed异常

在AS3里解析XML时遇到一“诡异”异常:TypeError: Error #1088: The markup in the document following the root element must be well-formed.

Air工程,SDK4.5,代码如下:

var f:File = new File("e:/demo.xml");
var fs:FileStream = new FileStream();
fs.open(f, FileMode.READ);
var xml:XML;
xml = XML(fs.readMultiByte(fs.bytesAvailable, "UTF-8"));
//后面省略

demo.xml文件内容如下:

<?xml version="1.0" encoding="utf-8"?>
<root>
    <item>abc</item>
</root>

异常堆栈:

TypeError: Error #1088: The markup in the document following the root element must be well-formed.
at XMLParse()[E:\Projects\XMLParse\src\XMLParse.as:15]
at runtime::ContentPlayer/loadInitialContent()
at runtime::ContentPlayer/playRawContent()
at runtime::ContentPlayer/playContent()
at runtime::AppRunner/run()
at ADLAppEntry/run()
at global/runtime::ADLEntry()

这段逻辑在之前执行过N次未出过问题,现在诡异了- -

开始解决

- 阅读剩余部分 -