简体   繁体   English

Flex:即使XML格式正确,也会出现有关“格式正确”标记的错误消息

[英]Flex: Error message about “well-formed” markup, even though XML is well-formed

I am reading attempting to load XML from a ByteArray as follows: 我正在读取尝试从ByteArray加载XML的信息,如下所示:

var xmlString:String = myByteArray.readUTFBytes(numBytes);
var myXML:XML = new XML(xmlString);

When I do that, I receive the following runtime error on the XML constructor when I run in Flash Player 9: 这样做时,在Flash Player 9中运行时,在XML构造函数上收到以下运行时错误:

TypeError: Error #1088: The markup in the document following the root element must be well-formed. TypeError:错误#1088:根元素后的文档中的标记必须格式正确。

This error message doesn't occur in Flash Player 10. I can use the debugger to verify that the XML looks well-formed. 在Flash Player 10中不会发生此错误消息。我可以使用调试器来验证XML的格式是否正确。 The XML is in UTF-8. XML使用UTF-8。

The solution to this particular problem for me was that there was an unnecessary Byte Order Mark at the very beginning of the file, which I had to remove. 对我来说,这个特殊问题的解决方案是在文件的开头有一个不必要的字节顺序标记 ,我必须将其删除。 Upon inspecting the file with a hex editor, I saw the following as the leading bytes in the file: 使用十六进制编辑器检查文件后,我看到以下内容作为文件中的前导字节:

EF BB BF EF BB高炉

The Flash Player 9 runtime apparently has a problem with this Byte Order Mark on a UTF-8 file, which is unnecessary since there is no byte ordering in UTF-8, as opposed to UTF-16 and UTF-32. Flash Player 9运行时显然在UTF-8文件上具有此字节顺序标记问题,这是不必要的,因为与UTF-16和UTF-32相比,UTF-8中没有字节顺序。 Flash Player 10 has no problem with this leading Byte Order Mark. Flash Player 10对此前导字节顺序标记没有问题。

That explains, why this other blog entry documents that the following solution worked for them: 这就说明了为什么其他博客条目记录了以下解决方案适用于他们的原因:

xmlString = xmlString.substr(1);

That particular solution didn't quite work for me, since it shifted the runtime error to Flash Player 10 users, instead of Flash Player 9 users. 该特定解决方案对我而言不太有效,因为它将运行时错误转移到Flash Player 10用户,而不是Flash Player 9用户。 Since we had control of the XML input, we could simply modify that, but if the XML came from a source we didn't control, I suppose we could have tested the ByteArray for the leading BOM, and skipped it as shown above. 由于我们可以控制XML输入,因此我们可以简单地对其进行修改,但是如果XML来自我们无法控制的源,我想我们可以测试ByteArray作为领先的BOM并跳过它,如上所示。

Several blog entries were helpful in confirming that the BOM was the problem, such as this entry , in which a commenter states that his solution to the same 1088 runtime error was: 几个Blog条目有助于确认BOM是问题所在,例如this 条目 ,其中评论者指出他对同一1088运行时错误的解决方案是:

For me the problem was XML saved in UTF with BOM. 对我来说,问题是XML用BOM保存在UTF中。

Also, this other blog entry provided more confirmation of the same problem occurring in Java: 此外, 此其他博客条目还提供了更多有关Java中发生的相同问题的确认:

When dealing with a UTF-8 encoded RSS feed, this three-byte pattern (0xEF 0xBB 0xBF) in >the prolog can cause all sorts of interesting XML parsing problems 在处理UTF-8编码的RSS提要时,>序言中的此三字节模式(0xEF 0xBB 0xBF)可能导致各种有趣的XML解析问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM