Flex: How to determine if XML is well formatted?

I have a function that loads in some XML that looks like this:

private function onXMLLoad(e:Event):void
            {
                trace(e.target.data);
                hideLoading();
                DataModel.instance.data = XML(e.target.data);
                updateSelections();
                toggleExpand();
            }

If the XML data that is being loaded is poorly formed, for example, the open tag is not closed. I get a message that XML should be well formatted. I actually never plan to download XML, which is not well formatted, but in case this ever happens, I would rather be able to process it somehow. First of all, is there a way to determine if the uploaded data is well formed before using it as XML, and if possible, try to fix it?

+3
source share
2

try/catch:

try {
  DataModel.instance.data = XML(e.target.data);
} catch (err:TypeError) {
  //handle error
}
+3

AFAIK, Flex/AS3, XML, .

XML ( , ), , , , .

/ XML AS3 ​​ XML. , , XML , .

+1

Source: https://habr.com/ru/post/1707871/


All Articles