Вход

Просмотр полной версии : XML и flash (доступ к дереву)


Snut
24.10.2007, 14:13
Есть XML вида:

<?xml version="1.0" encoding="utf-8"?>
<texts>
<part title="Some title">
<![CDATA[Some text]]>
</part>
<part title="Some title">
<![CDATA[Some text]]>
</part>
</texts>


гружу его вот так:

my_xml = new XML()
my_xml.load("site.xml")
my_xml.onLoad=function(success) {
if(!success || this.status){
return this.customErrorHandler(this.status, success)
}
this.customParsingProcedure()
}
my_xml.customParsingProcedure = function (){
trace("XML loaded"); // говорит что лоадед
_root.link_to_node = _root.my_xml.firstChild;
trace(_root.link_to_node.attributes.name) // выводит undefined
}
my_xml.customErrorHandler = function (status, success){
trace("loaded: " + success +" valid: " + !this.status)
trace('XML not loaded');
}


помогите добраться до нодов и имен атрибутов пожалуйста..
соответственно для атрибута в 1 ноде title1=Some title, и text1=Some text
чет ничего не получается...

Fernando Costa
24.10.2007, 14:33
а где в твоем XML аттрибут name? я вижу только аттрибут title

Snut
24.10.2007, 14:49
Fernando Costa, по утру еще и не такое бывает, проблема решена. но вот незадача...

грузим так:

my_xml = new XML()
my_xml.ignoreWhite = true;
var url:String = "site.xml";
my_xml.load(url);
my_xml.onLoad=function(success) {
if(!success || this.status){
return this.customErrorHandler(this.status, success)
}
this.customParsingProcedure()
}
my_xml.customParsingProcedure = function (){
trace("XML loaded");
trace("XML Status: "+my_xml.status);
_root.link_to_node = _root.my_xml;
_root.link_to_node = _root.link_to_node.firstChild.firstChild;
title1 = _root.link_to_node.attributes.title;
text1 = _root.link_to_node.firstChild;
_root.link_to_node = _root.link_to_node.nextSibling;
title2 = _root.link_to_node.attributes.title;
text2 = _root.link_to_node.firstChild;
_root.link_to_node = _root.link_to_node.nextSibling;
title3 = _root.link_to_node.attributes.title;
text3 = _root.link_to_node.firstChild;
_root.link_to_node = _root.link_to_node.nextSibling;
title4 = _root.link_to_node.attributes.title;
text4 = _root.link_to_node.firstChild;
_root.link_to_node = _root.link_to_node.nextSibling;
title5 = _root.link_to_node.attributes.title;
text5 = _root.link_to_node.firstChild;
}
my_xml.customErrorHandler = function (status, success){
trace("loaded: " + success +" valid: " + !this.status)
trace('XML not loaded');
}

далее заполнение динамических текстовых полей:

this.main_tf_mc1.main_tf.htmlText = text1;
this.title_tf_mc1.title_tf.htmlText = title1;


однако html теги в тексте отображаются "as is" например <p align="left"> и т.д.
всем полям поставлена галока Render text as HTML.
вот понять и не могу... че он н хочет теги кушать...

Snut
24.10.2007, 15:07
Проблема решена:
text1 = _root.link_to_node.firstChild;
меняем на
text1 = _root.link_to_node.firstChild.nodeValue;

эх.... учиться и учиться мне еще..