xml version="1.0" encoding="utf-8"?>
cc
var tmpByte:ByteArray = event.currentTarget.data;
var tmpText:String = "";
var tmpXml:XML;
try
{
tmpXml = new XML(tmpByte.readUTFBytes(tmpByte.length));
tmpText = tmpXml.toString();
if(!(tmpText.substr(0,1) == "<" && tmpText.substr(tmpText.length - 1, 1) == ">"))
{
tmpXml = null;
}
else
{
tmpText = tmpXml.toString();
}
}
catch (error:Object) { tmpXml = null; }
if (tmpXml == null)
{
try
{
tmpByte.uncompress(CompressionAlgorithm.ZLIB);
tmpXml = new XML(tmpByte.readUTFBytes(tmpByte.length));
tmpText = tmpXml.toString();
if(!(tmpText.substr(0,1) == "<" && tmpText.substr(tmpText.length - 1, 1) == ">"))
{
tmpXml = null;
}
else
{
tmpText = tmpXml.toString();
}
}
catch (error:Object) { tmpXml = null; }
if (tmpXml == null)
{
tmpText = tmpByte.readUTFBytes(tmpByte.length);
}
}
if (tmpXml == null)
{
trace("此字符不是XML");
}
else
{
trace("此数据是XML")
}