Thanks Gordon, that works great!!!

 

Michael

 


From: flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com] On Behalf Of Gordon Smith
Sent: Tuesday, June 27, 2006 4:01 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Re: help getting xml attribute names

 

x.attributes()[i].name()) will give you the name of the ith attribute.

 

Another syntax for this is [EMAIL PROTECTED]()

 

- Gordon

 


From: flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com] On Behalf Of Michael
Sent: Monday, June 26, 2006 3:02 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Re: help getting xml attribute names

 

Thanks Chas, but I am trying to get the names of the attributes.  I am getting dynamic data out of a database in XML form and I need to know the attribute names from the XML.  I just want the attribute names at the parent level.  In the sample I have written I would get “id” and “task”.

 

Thanks for your help, I will definitely look at the resource you mentioned.

 

Michael

 


From: flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com] On Behalf Of exporta_lite
Sent: Monday, June 26, 2006 4:23 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: help getting xml attribute names

 

--- In [EMAIL PROTECTED]ups.com, "Michael" <[EMAIL PROTECTED].> wrote:
<snip>

> I am trying to get the attribute names from mygroup...

<snip>

>
> <mygroup id="1" task="do this">
> <mychild id="1.1" task="do this" tools="hammer"/>
> <mychild id="1.2" task="do this" tools="wrench"/>
> </mygroup>
>

Suppose x:XML is the XML you show above. The "myChild" tags are
already accessible "as if" they were an array; for example, you can say

trace(x.myChild[0].toXMLString());

which will output

<mychild id="1.1" task="do this" tools="hammer"/>

Also, to access an attribute, you can use any of the following:

trace(x.myChild[0].attribute("id"));
trace(x.myChild[[EMAIL PROTECTED]"id"]);
trace(x.myChild[[EMAIL PROTECTED]);

all of which will output the string "1.1".

To use the XML as an array (sort of), you can use code such as:

for (i=0; i<x.myChild.length(); i++) {
trace(i+" id "+x.myChild[[EMAIL PROTECTED]);
}

x.myChild.length() returns the number of elements which are tags of
the type "myChild" (note the parens; it's ".length()", not ".length").

All this and more (e.g., the ability to only refer to myChild tags
which have the attribute tool=="hammer") can be found in the help docs
under:

Programming ActionScript 3.0 > Core ActionScript Data Types and
Classes > Working with XML

Cheers - Chas

__._,_.___

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com





SPONSORED LINKS
Web site design development Computer software development Software design and development
Macromedia flex Software development best practice


YAHOO! GROUPS LINKS




__,_._,___

Reply via email to