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>
开发者_JAVA技巧 <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?
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);
}
精彩评论