Like this article? We recommend
Example
The following example is a very small XML file that I wrote so that we could spend our time parsing it with XPath:
<?xml version="1.0" encoding="ISO-8859-1"?> <root> <node att="a0">0</node> <node att="a1">1</node> <node att="a2">2</node> <node att="a3">3</node> </root>
Before we start parsing this XML, we need to create a Flash file that will import the XPathAPI class and load the XML. Once you have a Flash movie created, write the following code:
import mx.xpath.XPathAPI; var xml = new XML(); xml.ignoreWhite = true; xml.load("test.xml"); xml.onLoad = function(success:Boolean) { if(success) { // This is where the code will go when you test the samples } else { trace("Error loading XML"); } }
Now that we have the code in place, we can start parsing with the XPathAPI. Let’s get started!