Great utility Cliff, thanks! One problem I've come across is when attempting to load xml from a utf-8 encoded file which includes the 3-byte BOM up front. The xml constructor baulks at trying to parse the string read from the file stream as it ignores the BOM. I got around this by overriding the XMLDataProxy.read() method as follows:
override protected function read():XML { // Read the database file into an XML object and return it var dbStream:FileStream; dbStream = new FileStream(); dbStream.open(dbFile, FileMode.READ); // Accomodate byte order marker if (((dbStream.readUnsignedByte() << 16) | (dbStream.readUnsignedByte() << 8) | dbStream.readUnsignedByte()) ^ 0xEFBBBF) { dbStream.position = 0; } var dbXML:XML = XML(dbStream.readUTFBytes(dbStream.bytesAvailable)); dbStream.close(); return dbXML; } Cheers!
|