Just posted the following bug report to the adobe bugs site.
Steps to reproduce:
Construct an XML variable with no explicit namespaces and any xml: attribute such as xml:lang or xml:id. E4X will correctly construct an implicit namespace for xml:, but will not assign the xml prefix to it, as such you end up with a default namespace which now applies to anything in your XML that doesn’t explicitly have another namespace associated with it.
Here’s a sample flex app that demonstrates the issue.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
<mx:Script>
<![CDATA[
private function init():void
{
var x:XML = <root xml:lang="en"><element/></root>
ta.text = x.toXMLString();
}
]]>
</mx:Script>
<mx:TextArea id="ta" width="100%" height="100%"/>
</mx:Application>
Actual Results:
<root lang="en" xmlns="http://www.w3.org/XML/1998/namespace">
<element/>
</root>
Notice that the root and element elements now incorrectly exist in the http://www.w3.org/XML/1998/namespace namespace.
Expected Results:
<root someprefix:lang="en" xmlns:someprefix="http://www.w3.org/XML/1998/namespace">
<element/>
</root>
Where someprefix is probably xml…
Workaround (if any):
- The xml:lang element was being added by our XML database and is not actually used by our app, so we simply removed it.
- You can specify xmlns:xml=”http://www.w3.org/XML/1998/namespace” in the root element and then the correct prefix is applied.