Groups | Blog | Home
all groups > flash data integration > june 2005 >

flash data integration : Accessing XML nodes


Bart_Sportpaleis
6/21/2005 12:00:00 AM
Suppose this your XML:

<content>
<author>
<book>
<title>this is the title</title>
<description>book description</description>
<book>
</author>
</content>

How can I easily retrieve the title using the nodeNames? I don't like this way
of accessing:

this.childNodes[0].childNodes[0].childNodes[0].childNodes[0].nodeValue

Just because it's confusing. I would like a notation like this or something
similar:

content.author.book.title.nodeValue()

Is this possible? Grtz, Bart
LuigiL
6/21/2005 9:38:05 PM
Wouldn't that be comfortable. Unfortunately, no. But, you can define an object
and turn the nodes into properties of that object. Than you would have access
with myObject.title
Otherwise you could extend the XMLNode class but that might be even more
confusing.
Another option: if you don't like working with this syntax, consider the
XMLConnector component along with a DataHolder or DataSet. This gives you the
option of binding the XML tree visually and you don't have to work with the
childNodes syntax.
chris.davis
6/24/2005 12:00:00 AM
Bart_Sportpaleis,

Try this freeware XPath implementation for ActionScript:
http://www.xfactorstudio.com

This library mimics XPath which makes traversing XML structures much easier.
You can refer to paths like directories (content/author/book/title) instead of
the awkward approach like you've shown. After I got fed up with the
"recommended" way to do this, I searched a while and found this and have been
much happier with it.

Hope this helps,

-Chris
AddThis Social Bookmark Button