[thelist] js xml2array
Christian Giordano
ml at nuthinking.com
Fri Oct 28 10:44:40 CDT 2005
Is there a very valid procedure to handle an xml object in JS?
Something like xpath for instance but not heavy like
http://mcc.id.au/xpathjs/ (112 kb!) since I would like to keep the
libraries light. A guy in the office did a smart and complex script to
handle xml files in ActionScript using complex trasformations. This is
part of the code:
var _transformedXML={};
_transformedXML.getLocalizedPhrase=function(lang,phraseID) {
return this[lang].phrase[phraseID][lang];
};
_transformedXML.getLocalizedLangName=function(lang,langAlt) {
return this[lang].lang[langAlt];
};
_transformedXML.getLocalizedAttribute=function(lang,attr) {
return this[lang].attributes[attr];
};
var _responseXML = new XML();
_responseXML.ignoreWhite = true;
_responseXML.onLoadSAX = {
language: function(tag) {
_saxCurrState={
lang: tag._attributes.id,
obj: _transformedXML[tag._attributes.id]={lang: {}, phrase: {},
attributes: tag._attributes}
};
},
lang: function(tag) {
trace(tag._attributes.id+": "+tag._value);
_saxCurrState.obj.lang[tag._attributes.id]=tag._value;
},
phrase: function(tag) {
_saxCurrState.phrase=_saxCurrState.obj.phrase[tag._attributes.id]={};
},
text: function(tag) {
_saxCurrState.phrase[tag._attributes.id]=tag._value;
}
};
_responseXML.onLoad = function(){
//usage
trace(_transformedXML.getLocalizedPhrase('it','translated')+_transformedXML.getLocalizedLangName('it','it'));
}
But I'm not able to understand entirely the whole thing. Is there
something similar in JS and maybe a tutorial that could explain it? What
do you use usually?
Many thanks, chr
--
___________________________________________________________________
{ Christian Giordano's site and blog @ http://cgws.nuthinking.com }
More information about the thelist
mailing list