How to Check for Valid XML in AS3

ActionScript 3 provides you with a "try-catch" error handling system you use to verify that XML content is valid before parsing the information in your pages. This feature lets you flag any XML files that do not contain a valid structure, so your program does not send errors to the user when it cannot parse the information.

Instructions

    • 1

      Right-click the ActionScript file you want to use to import the XML. Click "Open With" and select the ActionScript editor in the list of programs.

    • 2

      Locate the section of your code that opens the file. The following AS3 script opens an XML file:

      data = new XML("/folder/doc.xml");

    • 3

      Wrap the "try-catch" statement around the XML open document statement. The following code logs an error message if the XML is not valid:

      try {
      data = new XML("/folder/doc.xml");
      }
      catch (e:Error) {
      log.warn(e);
      }

Related Searches:

References

Comments

Related Ads

Featured