Mindon.IDEA

Air off, Mind on ~ / Javascript+Golang, Sci, Health… /

Use XML & XPath in Flash

BlogMS original blog key: 1000141979, blog id: airoff History stat: 浏览/评论:260/0 , 日期:2005年1月7日 11:01

/* mindon actionscript for flash 7.0 or upper

*/

import com.xfactorstudio.xml.xpath.*;

/ load xml into a textarea component with stylesheet /

function styleXML(areatxt, xmlfile, cssfile)

{

var areatxt, xmlfile, cssfile;

try {

//init TextArea component

areatxt.html = true;

areatxt.wordWrap = true;

areatxt.multiline = true;

areatxt.label.condenseWhite=true;

//load css

if(cssfile) {

var csstyle = new TextField.StyleSheet();

csstyle.load(cssfile);

areatxt.styleSheet = csstyle;

}

//load XML CONTENT

if(xmlfile) {

var xmlc = new XML();

xmlc.ignoreWhite = false;

xmlc.load(xmlfile);

xmlc.onLoad = function(success) {

if(success) {

areatxt.text = xmlc;

}

}

}

} catch(e) {

trace(e.description);

}

}

/ load xml file /

_global.xmldocs = {};

function loadXML(xmlfile, xmlfunc)

{

var xmlfile, xmlfunc;

try {

if(xmlfile && xmlfunc && typeof xmlfunc == "function") {

var xmlc = new XPathDocument();

xmlc.ignoreWhite = false;

xmlc.load(xmlfile);

xmlc.onLoad = function(success) {

if(success) {

xmldocs[xmlfile] = this;

xmlfunc(this);

}

}

}

} catch(e) {

trace(e.description);

}

}

//*/ loader example

function xmlLoader(xdoc)

{

var xdoc;

if(xdoc) {

var nod = xdoc.selectSingleNode("/mindon/name");

if(nod) {

if(String(nod.stringValue())=="derek.f") {

trace("true");

} else {

trace(nod.stringValue());

}

} else {

trace("cannot find node mindon/name");

}

} else {

trace("xml read fail");

}

}

//*/

Comments