PDA

View Full Version : getElementsByTagName problem


julian_lp
04-16-2006, 12:54 AM
given this dataset



<dataset name="dst_comments">
<root_comment_ganador>
<comment left="100" top="0" width="100" height="100">bla bla bla</comment>
<comment left="250" top="150" width="100" height="100">bla bla bla</comment>
</root_comment_ganador>
</dataset>









this code works quite fine


var comments = dst_comments.getFirstChild().getElementsByTagName("comment");
for(var i=0; i < comments.length; i++){
Debug.write('left: ' + comments[i].getAttr("left") + ' top: ' + comments[i].getAttr("top") + ' width: ' + comments[i].getAttr("width"));
}



But whenever I change the dataset structure, I can't be able to make it work again


<dataset name="dst_comments">
<root_comment_ganador>
<comment_ganador>
<comment left="100" top="0" width="100" height="100">bla bla bla</comment>
<comment left="250" top="150" width="100" height="100">bla bla bla</comment>
</comment_ganador>
</root_comment_ganador>
</dataset>


var comments = dst_comments.getFirstChild().getElementsByTagName("comment_ganador").getElementsByTagName("comment"); //this seems to be the correct "intuitive" way
for(var i=0; i < comments.length; i++){
Debug.write('left: ' + comments[i].getAttr("left") + ' top: ' + comments[i].getAttr("top") + ' width: ' + comments[i].getAttr("width"));
}

I also tried with
var comments = dst_comments.getElementsByTagName("comment");
var comments = dst_comments.getFirstChild().getElementsByTagName("comment_ganador/comment")





Any advice would be apreciated

regards - julian

vichai
04-16-2006, 06:26 PM
var comments = dst_comments.getFirstChild().getFirstChild().getEl ementsByTagName("comment");

julian_lp
04-16-2006, 08:44 PM
Originally posted by vichai
var comments = dst_comments.getFirstChild().getFirstChild().getEl ementsByTagName("comment");



Sadly, It doesn't work. Thanks anyway

Have anyone another idea to deal with this problem?

regards - julian

vichai
04-16-2006, 09:46 PM
source code that works for me.
<canvas debug="true">
<dataset name="dst_comments">
<root_comment_ganador>
<comment_ganador>
<comment left="100" top="0" width="100" height="100">bla bla bla</comment>
<comment left="250" top="150" width="100" height="100">bla bla bla</comment>
</comment_ganador>
</root_comment_ganador>
</dataset>

<script>
<![CDATA[
var comments = dst_comments.getFirstChild().getFirstChild().getEl ementsByTagName("comment");
for(var i=0; i < comments.length; i++){
Debug.write('left: ' + comments[i].getAttr("left") + ' top: ' + comments[i].getAttr("top") + ' width: ' + comments[i].getAttr("width"));
}
]]>
</script>
</canvas>

result in debug window
----------------------
left: 100 top: 0 width: 100
left: 250 top: 150 width: 100


What version that you use ( mine lps3.2 )

julian_lp
04-17-2006, 12:17 AM
You're absolutely right. I was just trying your code with a mistaken dataset.
You seem to be a kind of laszlo gurú ;)
Since when are you playing with laszlo?

regards - julian

vichai
04-17-2006, 04:59 PM
I first begin know about open laszlo for 6 months when I have to present about RIA and I have to evaluate many software solution. After that I forget about it.
I just begin dig laszlo one month because I want to evaluate it can use in my project or not.