Adobe-Runtime-Support
Adobe-Runtime-Support copied to clipboard
Error on constructing XML from a file created by Visual Studio
Problem Description
When constructing a XML
from a file created by Microsoft Visual Studio, the runtime would throw a TypeError
: Error #1088: The markup in the document following the root element must be well-formed.
Actually, there is a hidden character before the XML data. It's char code is 65279. Maybe AIR need to consider ignore hidden chars on constructing XML object.
Steps to Reproduce
Create a XML file by Visual Studio and write some text into it and then save the XML file as "test.xml" in the application dictionary.
Test the code:
package
{
import flash.display.Sprite;
import flash.filesystem.File;
import flash.filesystem.FileStream;
import flash.filesystem.FileMode;
[SWF(width="960", height="560", fps="24")]
public class test extends Sprite
{
private var fileStream:FileStream = new FileStream();
private var file:File = new File();
private var xml:XML;
private var string:String;
public function test()
{
file = File.applicationDirectory;
file.url += "test.xml";
fileStream.open(file, FileMode.READ);
fileStream.position = 0;
string = fileStream.readMultiByte(fileStream.bytesAvailable, "utf-8");
trace(string);
trace(string.charAt(0));
trace(string.charCodeAt(0));
xml = new XML(string);
}
}
}
Known Workarounds
Avoid create XML files by Visual Studio…
GPT told me it's the UTF-8 BOM (Byte Order Mark)…