Mailing List
Home
Flash Pro
Extending Flash
Flash Macromedia Developer
Subjects
Firework Effect
setInterval bug identified and fixed
setInterval bug identified and fixed
ScrollPane component doesn 't auto update
Help: MX 2004 How to script a print button to print the entire sli
Event Dispatcher between classes
memory management removeMovieClip /
MX2004 Dataset itemClassName
Order of events per frame
XML to Object help
Textfield prototype question
Flash and QuickTime VR
Reading and displaying RSS feeds in Flash MX
Flash MX 2004 Sucks
AW: [Flashcoders] Switch/Case vs If/else
AW: [Flashcoders] Switch/Case vs If/else
Flash Interface with 10mb xml file
Web Service Results
Listener Object 's best practice
 
Search:  
Power your search with and, or, +, -, or "some phrase" operators.
XML Iterator GOF style

XML Iterator GOF style

2004-02-11       - By Olaf Schmidtmann

 Back
Reply:     1     2  

Hi coders,

you may remember bokels XML iterator which was quite a popular afaik. I
converted it to AS2 and changed it to work with XMLNodes instead of XML.

The class is used like this:

iter = new XMLIteratorGOF(myXML);
result_array = new Array();
for( xmlIter.first(); xmlIter.hasNext(); xmlIter.next()){
   var currentNode = xmlIter.current();
   result_array.push(currentNode.nodeName);
}
delete iter;


The problem is the hasNext() method which does not allow to retrieve the
last node in xml structure because it returns false when reaching the second
last node.

public function hasNext():Boolean
{
   return node.hasChildNodes() || node.nextSibling != null ||
stack.length >0;
}

If you use an XML this misbehavior does not occur because (I guess) there is
something left at the last position. I did not investigate this in detail.

A quick work-around would be to introduce a variable that is set to 0 in the
first() method. The hasNext() method would look like this and - to be exact
- would not deserve its name any more. Anyway, my approach is to get this
iterator to good use.

public function hasNext():Boolean
{
   /// KLUDGE: This is too bad! But without the stopper the last
element in a for loop will be left out.
   if(!(node.hasChildNodes() || node.nextSibling != null ||
stack.length >0)) stopper++;
   return stopper < 2;
}

I do not like this from the looks besides the method name which I want to
keep because the iterators should all be "slaved under " an iterator
interface. Maybe I miss something completely here? Is there a more elegant
solution without changing the whole thing? I 'd welcome any thoughs on this.

I did not post the complete iterator, here because I presume it is common
knowledge but if you like I may very well send it to you for further
investigation.


Cheers
Olaf

--
*** http://www.brainbits.net/ ***

=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
Supported by Fig Leaf Software
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
Be sure to check the archives and the wiki:
http://chattyfig.figleaf.com/
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
http://chattyfig.figleaf.com/cgi-bin/ezmlm-cgi?1:mss:103764
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
To unsubscribe send a blank e-mail to:
Normal Mode: flashcoders-unsubscribe@(protected)
Digest Mode: flashcoders-digest-unsubscrive@(protected)