Category Archives: XML/XSLT/XML Schema

Namespaces on Attributes with E4X in ActionScript 3

I recently came accross an odd behavior when adding namespaces to an attrubute using E4X. I needed to create an XML object like the following:

1
<body xml:lang="en" xmpp:version="1.0" xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:xmpp="urn:xmpp:xbosh" />

This XML element is created dynamically within the ActionScript code like this:

1
2
3
4
5
var body:XML = <body />;
var xml:Namespace = new Namespace("xml", "http://www.w3.org/XML/1998/namespace");
body.@xml::lang = "en";
var xmpp:Namespace = new Namespace("xmpp", "urn:xmpp:xbosh");
body.@xmpp::version = "1.0";

However, the output of the namespaces in the XML was off:

1
<body aaa:lang="en" aab:version="1.0" xmlns:aaa="http://www.w3.org/XML/1998/namespace" xmlns:aab="urn:xmpp:xbosh" />

I realize this is still valid, but the server was having issues with it. That’s when I discovered that I need to first add the namespaces to the XML element using addNamespace(). This then gave me the right output:

1
2
3
4
5
6
7
var body:XML = <body />;
var xml:Namespace = new Namespace("xml", "http://www.w3.org/XML/1998/namespace");
body.addNamespace(xml);
body.@xml::lang = "en";
var xmpp:Namespace = new Namespace("xmpp", "urn:xmpp:xbosh");
body.addNamespace(xmpp);
body.@xmpp::version = "1.0";

Hopefully this will save someone else an hour of banging his or her head against the wall.

Speaking at FlashBelt

I’m once again speaking at FlashBelt this year.  I’ll be speaking on the topic of E4X, the new technology for working with XML in ActionScript 3.  I gave a talk on XML at FlashBelt a few years ago and talked a bit about the future of XML in ActionScript including E4X.  Well, that future is finally here.

Patterson Consulting is also a development sponsor of FlashBelt this year.  Its a great conference and I’m glad to be able to participate.  See ya there!

Use XML to Populate Dependant Select Lists

I have a new article that was recently published at Community MX titled Use XML to Populate Dependant Select Lists.

“Nearly everyone has seen the classic Dependant Select Lists. It’s a great user interface technique where you have two or more select form elements and the selection of one list changes the contents of the next list. This is commonly done with City and State selection interfaces. This tutorial will demonstrate how to build Dependant Select Lists and populate the lists using an XML data file.”