XML,类型错误:错误 #1088:中的标记 [英] XML, TypeError: Error #1088: The markup in
问题描述
谁能看出获取 XML 的代码或 XML 文件本身有什么问题?对我来说它看起来很好,我没有看到错误的原因:
Can anyone see whats wrong with either the code to grab the XML or the XML file itself? It looks well formed to me and I don't see the cause of the error:
发生了类型错误:类型错误:错误 #1088:文档中根元素后面的标记必须格式正确.
var file:String = 'config.xml';
var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest(file);
loader.load(request);
loader.addEventListener("complete", onComplete);
loader.addEventListener("ioError", onIOError);
private function onIOError(event:Event):void
{
trace("IOERROR (maybe XML file does not exit or have an incorrect name)");
}
private function onComplete(event:Event):void
{
var loader:URLLoader = event.target as URLLoader;
if (loader != null) {
try {
var settings:XML = new XML(loader.data);
} catch (e:TypeError) {
trace("A TypeError has occured: \r\t" + e);
}
} else {
trace("Loader is not a URLLoader!");
}
}
配置文件
<?xml version="1.0" encoding="UTF-8"?>
<settings>
<setting1>1</setting1>
<showDebug>2</showDebug>
<someOtherSetting>3</someOtherSetting>
</settings>
推荐答案
您是用什么创建 XML 文档的?
What did you create the XML document in?
我前几天发生了类似的事情,根据 text/xml 编辑器,它可能会在开头添加一个字节顺序标记 维基百科 BOM .这会立即使 XML 文件无效.尝试将您拥有的内容复制并粘贴到记事本中并重新保存.
I had something similar occur the other day, depending on the text/xml editor it may add a Byte Order Mark to the beginning Wikipedia BOM . This instantly invalidates the XML file. Try copying and pasting what you have into notepad and re-saving it.
或者,如果您有可用的 Linux 机器,则 BOM 将在 VI 中显示为",您可以将其删除.
Or, if you have a Linux machine available, the BOM will appear in VI as '' and you can remove it.
另外,仅供参考,BOM的utf编码是'\ufeff'
Also, just for reference, the utf encoding for the BOM is '\ufeff'
这篇关于XML,类型错误:错误 #1088:中的标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!