|
Bgx Xml Serialization Classes (Flash MX 2004) :
Basic deserialization example
Flash output
This example corresponds with the file XmlExample.fla
that is supplied with the component. The following code loads the
XML file sample.xml,
parses it using the BgxDesObject class and then accesses some of
the properties to populate a text box called tbxDisplay.
//import the class
import bgx.BgxDesObject;
//global variable to hold deserialized sample data
var SampleData:Object;
//load xml from external file
var sampleXML:XML = new XML();
sampleXML.ignoreWhite = true;
sampleXML.onLoad = parseSampleData;
sampleXML.load("sample.xml");
//parse sample data
function parseSampleData() {
var rootNode:XMLNode = sampleXML.firstChild;
SampleData = new BgxDesObject();
SampleData.xmlNode = rootNode;
SampleData.onParsed = setDisplay;
SampleData.parse();
}
function setDisplay(){
//get the site name
tbxDisplay.text = "Site name: "
+ SampleData.label + "\n\n";
//get first level folders
tbxDisplay.text += "First level folders:\n";
for (var i = 0; i < SampleData.folder.length;
i++)
{
tbxDisplay.text
+= " " + SampleData.folder[i].label + "\n";
}
//get the description from the bgx:comment
element
tbxDisplay.text += "\nComment:\n";
tbxDisplay.text += SampleData.bgx_cln_comment[0].description
+ "\n";
//get the namespace declaration from the
root element
tbxDisplay.text += "\nCustom namespace:\n";
tbxDisplay.text += SampleData.xmlns_cln_bgx
+ "\n";
//display text from the exampleNode text
node
tbxDisplay.text += "\nText node example:\n";
tbxDisplay.text += SampleData.exampleNode[0].nodeText;
}
For further information please contact info@bgxcomponents.com.
|