<root xmlns:space="http://www.something.com"> <space:tag> <node>Hello, world!</node> </space:tag> </root>
Assuming that this XML has been parsed into an XML variable named xml, we could determine the contents of the node node using the following code:
namespace space = "http://www.something.com"; var helloWorld: String = xml.space::tag.node.toString( );
That is, we are able to declare a namespace identifier by using the namespace keyword, and then reference it in our E4X statements to select the appropriate nodes (using the same notation that we would use to reference custom namespaces in ActionScript 3). Note that the identifier we declare does not have to match the one used in the XML document - only the namespace URI has to match. The example below is equally correct:
namespace different = "http://www.something.com"; var helloWorld: String = xml.different::tag.node.toString( );
Using this technique avoids the need to manipulate XML content before it is parsed; it is simpler and avoids the chance of incorrectly preprocessing the data.
No comments:
Post a Comment