Actually,
now I have a follow-up question. I've managed to use E4X to parse
the XML now, but, for some XML documents, there are attributes on some of the
items. For instance, in comparison to the previous XML I posted, some are
now...
<Item xmlns="some.namespace.com"> //
the attribute of xmlns="..." is new
<ItemID>110000579339</ItemID>
<Site>US</Site>
<Title>Halo 2 (Xbox)</Title>
<Currency>USD</Currency>
<SiteHostedPicture>
<GalleryType>http://somesite.com/somepicture.jpg</GalleryType>
</SiteHostedPicture>
<PaymentMethods>PayPal</PaymentMethods>
</Item>
So, with
the new attribute on the Item tag, I can't seem to access any children using
the same calls anymore. For instance, when I go some_label.text =
xml_object.ItemID, it is now blank, when it used to be filled
before...?
I've
tried using the @ attribute operator in calls such as some_label.text =
xml_object.(@xmlns == "some.namespace.com").ItemID),
but still nothing.
Thanks
again
Charles
--- In flexcoders@yahoogroups.com,
"Charles" <[EMAIL PROTECTED]> wrote:
>
> Great. Got it! Thanks for the help everyone!
>
>
>
> --- In flexcoders@yahoogroups.com,
"Peter Hall" peterjoel@
> wrote:
> >
> > XMLDocument is the old XML object, which has firstChild,
> nextSibling etc.
> > Use XML to use e4x.
> >
> > public var xml_object:XML = new XML();
> >
> > Peter
> >
> >
> > On 6/7/06, Charles charles.bihis@ wrote:
> > >
> > > Hi guys,
> > >
> > > Thanks for the replies. But I should mention that I've tried
> that
> > > before. I get no output...blank. I actually used that before
> when my data
> > > provider was an ArrayCollection, or an HTTPService. But now
> that it's an
> > > XMLDocument, for some reason, it doesn't work, and the only
> thing that does
> > > is by using firstChild and lastChild. Just in case I am doing
> something
> > > totally wrong here, I'll try and be a little more specific.
> Here is a
> > > simpler version of what I am trying to do (if you are so
> inclined, you can
> > > grab the actual .mxml file
> here<http://charles.abstractations.com/test.mxml>
> > > in case you wanted to see a little clearer)...
> > >
> > >
> > >
> > > <?xml version="1.0" encoding="utf-8"?>
> > > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
> > > layout="vertical">
> > > <mx:Script>
> > > <![CDATA[
> > > public var xml_object:XMLDocument = new XMLDocument;
> > >
> > > public function ParseXML():void
> > > {
> > > xml_object.ignoreWhite = true;
> > > xml_object.parseXML("<Item>" +
> > >
> > > " <ItemID>110000579339</ItemID>" +
> > > " <Site>US</Site>" +
> > > " <Title>Halo 2 (Xbox)</Title>" +
> > > " <Currency>USD</Currency>" +
> > > " <SiteHostedPicture>" +
> > > "
>
<GalleryType>http://somesite.com/somepicture.jpg</GalleryType>"
> > > +
> > > " </SiteHostedPicture>" +
> > > " <PaymentMethods>PayPal</PaymentMethods>"
+
> > > "</Item>");
> > >
> > > everything.text = xml_object.firstChild.toString(); //
> returns full
> > > XML string - OK!
> > > //just_item_id = xml_object.Item.ItemID.toString(); //
> ERROR -
> > > "Access of possibly undefined property Item"
> > > //just_item_id = xml_object.Item.toString(); // ERROR -
> "Access of
> > > possibly undefined property Item"
> > > //just_item_id = xml_object.childNodes.Item; // no error,
> but
> > > displays nothing
> > > } // ParseXML
> > > ]]>
> > > </mx:Script>
> > >
> > > <mx:Label id="everything"/> <!-- should show
full xml after
> button is
> > > clicked -->
> > > <mx:Label id="just_item_id"/> <!-- should
only show ItemID
> after button
> > > is clicked -->
> > >
> > > <mx:Button label="click me"
click="ParseXML()"/>
> > > </mx:Application>
> > >
> > >
> > >
> > > Thanks for the help!
> > >
> > >
> > >
> > > Charles
> > >
> > >
> > >
> > >
> > > --- In flexcoders@yahoogroups.com,
"Tracy Spratt"
<tspratt@>
> wrote:
> > > >
> > > > Compare it to the Microsoft XML DOM, which has dozens of
> classes.
> > > > "XML", huh, one class? How can that be?
> > > >
> > > > Tracy
> > > >
> > > >
> > > >
> > > > ________________________________
> > > >
> > > > From: flexcoders@yahoogroups.com
> [mailto:flexcoders@yahoogroups.com]
On
> > > > Behalf Of Michael Schmalle
> > > > Sent: Tuesday, June 06, 2006 6:40 PM
> > > > To: flexcoders@yahoogroups.com
> > > > Subject: Re: [flexcoders] Alternative to firstChild,
lastChild
> and
> > > > nextSibling
> > > >
> > > >
> > > >
> > > > You got that right! E4x can do some crazy things. Sometimes
I
> wonder if
> > > > I am kidding myself at how easy it is to use :)
> > > >
> > > > Peace, Mike
> > > >
> > > > On 6/6/06, Tracy Spratt
tspratt@ wrote:
> > > >
> > > > Yep. And the subtext to my style of response is "If
you are
> not using
> > > > 2.0 yet, here is one very good reason to make the
move."
> > > >
> > > > Tracy
> > > >
> > > >
> > > >
> > > > ________________________________
> > > >
> > > > From: flexcoders@yahoogroups.com
> [mailto:flexcoders@yahoogroups.com]
On
> > > > Behalf Of Michael Schmalle
> > > > Sent: Tuesday, June 06, 2006 6:23 PM
> > > > To: flexcoders@yahoogroups.com
> > > > Subject: Re: [flexcoders] Alternative to firstChild,
lastChild
> and
> > > > nextSibling
> > > >
> > > >
> > > >
> > > > Tracy....
> > > >
> > > > :-( That is what I was getting to :) I guess being direct
> works ... HA
> > > >
> > > > Peace, Mike
> > > >
> > > > On 6/6/06, Tracy Spratt
< tspratt@
> > >
> > > > <mailto:tspratt@ > wrote:
> > > >
> > > > E4x:
> > > >
> > > > xml_object.PaymentMethods; //PayPal
> > > >
> > > > xml_object.SiteHostedPicture.GalleryType; //http://.....
> > > >
> > > >
> > > >
> > > > Tracy
> > > >
> > > >
> > > >
> > > > ________________________________
> > > >
> > > > From: flexcoders@yahoogroups.com
> [mailto:flexcoders@yahoogroups.com]
On
> > > > Behalf Of Charles
> > > > Sent: Tuesday, June 06, 2006 5:52 PM
> > > > To: flexcoders@yahoogroups.com
> > > > Subject: [flexcoders] Alternative to firstChild, lastChild
and
> > > > nextSibling
> > > >
> > > >
> > > >
> > > > Hi everyone,
> > > >
> > > >
> > > >
> > > > I am trying to parse some XML for relevant info using
> firstChild,
> > > > lastChild, and nextSibling. For instance, given an XML file
> like...
> > > >
> > > >
> > > >
> > > > <Item>
> > > > <ItemID>110000579339</ItemID>
> > > > <Site>US</Site>
> > > > <Title>Halo 2 (Xbox)</Title>
> > > > <Currency>USD</Currency>
> > > > <SiteHostedPicture>
> > > >
<GalleryType>http://somesite.com/somepicture.jpg</GalleryType>
> > > > </SiteHostedPicture>
> > > > <PaymentMethods>PayPal</PaymentMethods>
> > > > </Item>
> > > >
> > > >
> > > >
> > > > ...when I try to get the ItemID, I just go
> > > > xml_object.firstChild.firstChild. But, when I try and get
> things from
> > > > the bottom, I would have to go something like
> > > >
> xml_object.firstChild.firstChild.firstChild.firstChild.firstChild.fir
> stC
> > > > hild.firstChild (which would give me PaymentMethods...I
> think). I could
> > > > use xml_object.lastChild.firstChild, but that's not the
point.
> I would
> > > > just like to know if there is an alternative to this sort
of
> accessing
> > > > of the XML fields?
> > > >
> > > >
> > > >
> > > > My main concern is that for some XML files, the structure
is
> slightly
> > > > different (i.e. the <Site></Site> tags are not
there). So, the
> long
> > > > call to access PaymentMethods for one XML file would not
work
> on
> > > > another. Rather, it would return SiteHostedPicture for
those.
> Any help
> > > > would be great.
> > > >
> > > >
> > > >
> > > > Thanks
> > > >
> > > >
> > > >
> > > > Charles
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > --
> > > > What goes up, does come down.
> > > >
> > > >
> > > >
> > > >
> > > > --
> > > > What goes up, does come down.
> > > >
> > >
> > >
> > >
> >
>