Filtering data

Let's work with this xml:

<?xml version="1.0" encoding="UTF-8"?>
<index>
    <books>
	<book id='0'>
            <title>Thus Spoke Zarathustra</title>
	    <author>Friedrich Nietzsche</author>
	</book>
	<book id='1'>
	    <title>The Stranger</title>
	    <author>Albert Camus</author>
	</book>
	<book id='2'>
	    <title>The Idiot</title>
	    <author>Fyodor Dostoyevsky/author>
	</book>
	<book id='3'>
	    <title>Faust</title>
	    <author>Goethe</author>
	</book>
    </books>
</index>

The double dot (..)

The double-dot operator works for any level of nesting, and not just direct children.

Filtering Node Values

var authorList:XMLList =  xml..book.(author ==  "Goethe");

Filtering Attribute Information

var bookList:XMLList = xml..book.(@id ==  "3").title;

More than one conditions

var bookList:XMLList =  xml..book.(author ==  "Goethe" && title ==  "Faust").title;

Finding node index

var nodeIndex:int =  xml..book.(author ==  "Goethe").childIndex();
trace(nodeIndex); // traces '3'

Learning Resources

Check this tutorial for more.

And this.

Post A Comment

Anti-Spam Quiz: