Xml – How to remove a namespace from an XML document

actionscript-3apache-flexnamespacesweb servicesxml

In my Flex application, I call several .NET WebServices that return XML. However, these WebServices all return XML with a namespace. I cannot read/parse the XML without referencing the namespace, meaning that I have to include the following lines of code in each Class that calls a WebService:

private namespace PCRWebServices = "xxx.somename.web.services";

use namespace PCRWebServices;

I would like to eliminate the need for this static/hard-coded logic simply to read XML from a WebService.

Is there any way to "remove" the namespace from the XML, so that I can read it as a "normal" XML document?

I have a Class that I extend for every WebService call that handles results and faults:

private function faultHandler(event:FaultEvent):void
{

}

private function resultHandler(event:ResultEvent):void
{
    var resultXML:XML = new XML(event.result);
}

I would like to add some logic to the result handler to "convert" the XML. Any ideas?

This what trace(resultXML) returns:

<GetDataResult xmlns="xxx.somename.web.services">
  <DataSet>
    <Data>
      <IdNmb>15</IdNmb>
      <NameTxt>Hello</NameTxt>
    </Data>
    <Data>
      <IdNmb>16</IdNmb>
      <NameTxt>World</NameTxt>
    </Data>
    <Status>
      <Status>Success</Status>
    </Status>
    <ReturnCode>
      <ReturnCode>0</ReturnCode>
    </ReturnCode>
  </DataSet>
</GetDataResult>

Best Answer

Here's another regex solution. It will remove multiple namespaces, not just one.

private function resultHandler(event:ResultEvent):void
{
    var nsRegEx:RegExp = new RegExp(" xmlns(?:.*?)?=\".*?\"", "gim");

    var resultXML:XML = new XML(String(event.result).replace(nsRegEx, ""));        
}