First when you start working with XML in flex you are completely wondered about how easy the xpath like syntax is used. However some botlenecks might occur. One of them is using namespaces. Consider the following example:

<?xml version="1.0" encoding="UTF-8"?><report version="3.2.15" xmlns="http://www.len.ro/report">    <item name="user">len</item></report>

First approach is to do something like:

var myXML:XML = XML(event.result);trace("XML: " + myXML.item.@name);

you will see nothing and start wondering what you are doing wrong. Some time later you realize it’s namespace related and you try (according to flex doc) to do this:

var myXML:XML = XML(event.result);var ns:Namespace = myXML.namespace();default xml namespace = ns;trace("XML: " + myXML.item.@name);

you will get an ugly error similar to:

verify com.mccsoft.diapason.report::report/_report_HTTPService1_i()                        stack:                        scope: [global Object$ flash.events::EventDispatcher$ flash.display::DisplayObject$ flash.display::InteractiveObject$ flash.display::DisplayObjectContainer$ flash.display::Sprite$ mx.core::FlexSprite$ mx.core::UIComponent$ mx.core::Container$ mx.core::LayoutContainer$ mx.modules::Module$ com.mccsoft.flex.extras::DiapasonModule$ com.mccsoft.diapason.report::report$]                          locals: com.mccsoft.diapason.report::report *   0:debugfile "/phantom/mcc/diapason/client/flex/src;com/mccsoft/diapason/report;report.mxml"                        stack:                        scope: [global Object$ flash.events::EventDispatcher$ flash.display::DisplayObject$ flash.display::InteractiveObject$ flash.display::DisplayObjectContainer$ flash.display::Sprite$ mx.core::FlexSprite$ mx.core::UIComponent$ mx.core::Container$ mx.core::LayoutContainer$ mx.modules::Module$ com.mccsoft.flex.extras::DiapasonModule$ com.mccsoft.diapason.report::report$]                          locals: com.mccsoft.diapason.report::report *   3:debugline 7                        stack:                        scope: [global Object$ flash.events::EventDispatcher$ flash.display::DisplayObject$ flash.display::InteractiveObject$ flash.display::DisplayObjectContainer$ flash.display::Sprite$ mx.core::FlexSprite$ mx.core::UIComponent$ mx.core::Container$ mx.core::LayoutContainer$ mx.modules::Module$ com.mccsoft.flex.extras::DiapasonModule$ com.mccsoft.diapason.report::report$]                          locals: com.mccsoft.diapason.report::report *   5:getlocal0                        stack: com.mccsoft.diapason.report::report                        scope: [global Object$ flash.events::EventDispatcher$ flash.display::DisplayObject$ flash.display::InteractiveObject$ flash.display::DisplayObjectContainer$ flash.display::Sprite$ mx.core::FlexSprite$ mx.core::UIComponent$ mx.core::Container$ mx.core::LayoutContainer$ mx.modules::Module$ com.mccsoft.flex.extras::DiapasonModule$ com.mccsoft.diapason.report::report$]                          locals: com.mccsoft.diapason.report::report *   6:pushscope                        stack:                        scope: [global Object$ flash.events::EventDispatcher$ flash.display::DisplayObject$ flash.display::InteractiveObject$ flash.display::DisplayObjectContainer$ flash.display::Sprite$ mx.core::FlexSprite$ mx.core::UIComponent$ mx.core::Container$ mx.core::LayoutContainer$ mx.modules::Module$ com.mccsoft.flex.extras::DiapasonModule$ com.mccsoft.diapason.report::report$] com.mccsoft.diapason.report::report                          locals: com.mccsoft.diapason.report::report *   7:getlocal3VerifyError: Error #1025: An invalid register 3 was accessed.

after some more digging you realize you need to do something like that to get it working:

Choice 1:

<strong>var myNS:Namespace = new Namespace("http://www.len.ro/report");</strong>

public function onXMLReport(event:ResultEvent){var myXML:XML = XML(event.result);<strong>default xml namespace = myNS;</strong>trace("XML: " + myXML.item.@name);}

or

Choice 2:

public function onXMLReport(event:ResultEvent){var myXML:XML = XML(event.result);<strong>var myNS = myXML.namespace();</strong>trace("XML: " + myXML.<strong>myNS::</strong>item.@name);}