1

So i have this chunk of XML:

<?xml version="1.0" encoding="UTF-8"?>
<groups>
    <group>
        <image name="afp.jpg"/>
        <image name="agfa.jpg"/>
        <image name="americomp.jpg"/>
    </group>
    <group>
        <image name="canon.jpg"/>
        <image name="carestream.jpg"/>
        <image name="cmt.jpg" />
    </group>
    <group>
        <image name="ge.jpg"/>
        <image name="gtr.jpg"/>
        <image name="medlink.jpg" />
    </group>
    <group>
        <image name="pacsgear.jpg"/>
        <image name="philips.jpg"/>
        <image name="poskom.jpg" />
    </group>
    <group>
        <image name="radpro.jpg"/>
        <image name="sedecal.jpg"/>
        <image name="siemens.jpg" />
    </group>
    <group>
        <image name="sony.jpg"/>
        <image name="sotuna.jpg"/>
        <image name="sri.jpg" />
    </group>
    <group>
        <image name="tims.jpg"/>
        <image name="toshiba.jpg"/>
        <image name="ziehm.jpg" />
    </group>
    <group>
        <image name="zonare.jpg"/>
        <image name="unitedradiologysystems.jpg"/>
    </group>
</groups>

And inside the load complete event handler i have this:

var xDoc:XMLDocument = new XMLDocument();
var userXML:XML = XML(evt.target.data);
trace(userXML);
xDoc.parseXML(userXML.toXMLString());

I have a Group object defined that will store just a list of image names in an array. How do use the xDoc object to read in this data?

1 Answer 1

3

Why use the xDoc variable? XML is a native datatype in Flex that is great with E4X syntax as shown below (note: some error handling and null checking would probably be a good idea).

var images:XMLList = userXML.group.image as XMLList;
for each(var img:XML in images)
{
    trace(img.@name);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.