|
Bgx Xml Serialization Classes (Flash MX 2004) :
Serializing objects created with the BgxDesObject
class
Flash output
This example corresponds with the file SerializationExample.fla
that is supplied with the component. The following code loads the
XML file sample.xml,
parses it using the BgxDesObject class and then uses an instance
of the BgxSerObject class to re-serialize it using the default settings,
displaying the XML string created in a text field called tbxDisplay
and accesses the XML as XML to extract the label attribute
from the root element, displayed in the text field tbxRootLabel.
It furthermore sets the value of the text box tbxRootname as
the root name of the XML and the value of the text box tbxRootLabel
as the value of SampleData.label when the button btnSerialize
is clicked, and then re-serializes the data.
//import the classes
import bgx.BgxDesObject;
import bgx.BgxSerObject;
//global variables to hold data
var SampleData:Object;
var SerObj: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 = serialize;
SampleData.parse();
}
function serialize(pRootName:String)
{
SerObj = new BgxSerObject();
if (typeof pRootName != "undefined")
{
SerObj.rootName
= pRootName;
}
SerObj.sourceObject = SampleData;
SerObj.onSerialized = setDisplay;
SerObj.serialize();
}
function setDisplay()
{
tbxDisplay.text = SerObj.xmlString;
var serXml:XML = SerObj.getXML();
tbxRootLabel.text = serXml.firstChild.attributes["label"];
}
btnSerialize.onRelease = function()
{
if (tbxRootlabel.text != "")
{
SampleData.label
= tbxRootlabel.text;
}
if (tbxRootname.text != "")
{
serialize(tbxRootname.text);
}
}
For further information please contact info@bgxcomponents.com.
|