Recursive XML parsing in Flex

When I had to parse a long book.xml for CD Splitter tool I was working on recently, I had a hard time to get the xml parsed effectively and with minimum code lines.  And I was hell bent, that i’ll not bother the good old friend google for this. Finally, after few attempts I got the solution.

private function onTemplateXMLLoad(event:ResultEvent):void

{

parseTemplateXML(XML(event.result));

}

private function parseTemplateXML(objXML:XML):void

{

if(objXML != null)

{

for each(var item:XML in objXML.children())

{

// trace("hasComplexContent*** : "+item.hasComplexContent());

if(item.hasComplexContent())

{

// recursive call

parseTemplateXML(item);

}

else

{

// this is the node value you are seeking

}

}

}

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s