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 - 21 Jun 2005 22:38 GMT
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 - 24 Jun 2005 05:52 GMT
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