Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AS3 XML object not throwing exception if invalid data is given?

I remember darkly that the XML class in AS3 would throw an exception if you tried to give it data in it's constructor that was not a valid XML string. But now I got a case where the XML happily takes every kind of data no matter it's valid XML or not...

var xml:XML;
try
{
    xml = new XML("Some bogus string content.");
    _valid = true;
}
catch (err:Error)
{
    _valid = false;
}

... am I missing something??

Update: Qname somehow is null but somehow it's not, see here:

var qname:QName = xml.name();
if (!qname.localName)
{
    _valid = false;
}

... throws an exception. Obvioulsy qname is null! But ...

var qname:QName = xml.name();
if (!qname || !qname.localName)
{
    _valid = false;
}

... doesn't throw any exception. qname seems not to be null. WTH?

like image 697
BadmintonCat Avatar asked Feb 18 '26 13:02

BadmintonCat


1 Answers

Your example should give XML object with no name and with nodeKind equal to "text". This is how text nodes are represented in XML. In addition to try/catch, you may check for name().

like image 196
alxx Avatar answered Feb 20 '26 17:02

alxx



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!