XML Namespaces

This article isn't to teach you what namespaces are, how they work, and why you would use them, this article is just to help you take the first step to figuring out how to parse xml with namespaces in it.

var xml:XML = <root>
	<h:table xmlns:h="http://www.w3.org/TR/html4/">
	  <h:tr>
	    <h:td>Apples</h:td>
	    <h:td>Bananas</h:td>
	  </h:tr>
	</h:table>
 
	<f:table xmlns:f="http://www.w3schools.com/furniture">
	  <f:name>African Coffee Table</f:name>
	  <f:width>80</f:width>
	  <f:length>120</f:length>
	</f:table>
 
</root>
 
trace("Not using a namespace");
trace(xml.table); // Nothing
 
var trNs:Namespace = new Namespace("http://www.w3.org/TR/html4/");
var furnitureNs:Namespace = new Namespace("http://www.w3schools.com/furniture");
 
trace("Using a namespace");
trace(xml.trNs::table);
trace(xml.furnitureNs::table);
 
 
// You can also set the default xml namespace if you are repeatedly using the same namespace.
default xml namespace = new Namespace("http://www.w3.org/TR/html4/");
//trace("Using a namespace");
//trace(xml.table);