| Package | Top Level |
| Class | public final class Namespace |
| Inheritance | Namespace Object |
This class (along with the XML, XMLList, and QName classes) implements powerful XML-handling standards defined in ECMAScript for XML (E4X) specification (ECMA-357 edition 2).
View the examples. See also| XML, XMLList, QName, ECMAScript for XML (E4X) specification (ECMA-357 edition 2) |
| Property | Defined by | ||
|---|---|---|---|
![]() | constructor : Object
A reference to the class object or constructor function for a given object instance.
| Object | |
| prefix : String
The prefix of the namespace.
| Namespace | ||
![]() | prototype : Object
[static]
A reference to the prototype object of a class or function object.
| Object | |
| uri : String
The Uniform Resource Identifier (URI) of the namespace.
| Namespace | ||
| Function | Defined by | ||
|---|---|---|---|
|
Creates a Namespace object given the
uriValue parameter. | Namespace | ||
|
Creates a Namespace object, given the
prefixValue and uriValue parameters. | Namespace | ||
![]() |
Indicates whether an object has a specified property defined.
| Object | |
![]() |
Indicates whether an instance of the Object class is in the prototype chain of the object specified
as the parameter.
| Object | |
![]() |
Indicates whether the specified property exists and is enumerable.
| Object | |
![]() |
Sets the availability of a dynamic property for loop operations.
| Object | |
|
This function is equivalent to the
Namespace.uri property. | Namespace | ||
![]() |
Returns the primitive value of the specified object.
| Object | |
prefix:String [read-write] public function get prefix():String
public function set prefix(value:String):void
uri:String [read-write] public function get uri():String
public function set uri(value:String):void
public function Namespace(uriValue:*)
uriValue parameter.
The values assigned to the uri and prefix properties
of the new Namespace object depend upon the type of value passed for the uriValue parameter:
prefix and uri properties are set to the empty string.uri property is set to the QName object's uri property.uri property.uriValue:* — The Uniform Resource Identifier (URI) of the namespace.
|
public function Namespace(prefixValue:*, uriValue:*)
prefixValue and uriValue parameters.
This constructor requires both parameters.
The value of the prefixValue parameter is assigned to the prefix
property in the following manner:
undefined is passed, prefix is set to undefined.isXMLName() function, it is converted to a string and assigned to the prefix property.prefix property is set to undefined.The value of the uriValue parameter is assigned to the uri
property in the following manner:
uriValue parameter, the uri property is set to the value of the QName object's uri property.uriValue parameter is converted to a string and assigned to the uri property.prefixValue:* — The prefix to use for the namespace.
|
|
uriValue:* — The Uniform Resource Identifier (URI) of the namespace.
|
public function toString():String
Namespace.uri property.
Returns
String —
The Uniform Resource Identifier (URI) of the namespace, as a string.
|
myXML and assign it to the return value of
getRSS(). The getRSS() method defines an XML object that contains several namespaces
and returns that XML object.parseRSS() method with
myXML passed to it. In parseRSS(), the default XML namespace is defined as
rss and an XMLList variable is defined by assigning the list of item
objects in myXML. Then an Array is created and populated with various nodes within
myXML.item and the Array is then returned.for loop and three calls to
trace().
package {
import flash.display.Sprite;
public class E4XNamespaceExample extends Sprite {
private var rss:Namespace = new Namespace("http://purl.org/rss/1.0/");
private var rdf:Namespace = new Namespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#");
private var dc:Namespace = new Namespace("http://purl.org/dc/elements/1.1/");
public function E4XNamespaceExample() {
var myXML:XML = getRSS();
var rssItems:Array = parseRSS(myXML);
var len:uint = rssItems.length;
for(var i:uint; i < len; i++) {
trace(rssItems[i].title);
trace(rssItems[i].creator);
trace(rssItems[i].date);
// Macromedia Flash Developer Center
// Macromedia
// 2005-08-08
// Flex Developer Center
// Macromedia
// 2005-10-16
}
}
private function parseRSS(rssXML:XML):Array {
default xml namespace = rss;
var items:XMLList = rssXML.item;
var arr:Array = new Array();
var len:uint = items.length();
for(var i:uint; i < len; i++) {
arr.push({title:items[i].title, creator:items[i].dc::creator, date:items[i].dc::date});
}
return arr;
}
private function getRSS():XML {
var myXML:XML = <rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://purl.org/rss/1.0/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
>
<channel rdf:about="http://www.xml.com/cs/xml/query/q/19">
<title>Test RSS</title>
<link>http://www.macromedia.com/</link>
<description>This is a test RSS document.</description>
<language>en-us</language>
<items>
<rdf:Seq>
<rdf:li rdf:resource="http://www.macromedia.com/devnet/flash/"/>
<rdf:li rdf:resource="http://www.macromedia.com/devnet/flex/"/>
</rdf:Seq>
</items>
</channel>
<item rdf:about="http://www.macromedia.com/devnet/flash/">
<title>Macromedia Flash Developer Center</title>
<link>http://www.macromedia.com/devnet/flash/</link>
<description>Welcome to the Flash Developer Center</description>
<dc:creator>Macromedia</dc:creator>
<dc:date>2005-08-08</dc:date>
</item>
<item rdf:about="http://www.macromedia.com/devnet/flex/">
<title>Flex Developer Center</title>
<link>http://www.macromedia.com/devnet/flex/</link>
<description>Welcome to the Flex Developer Center</description>
<dc:creator>Macromedia</dc:creator>
<dc:date>2005-10-16</dc:date>
</item>
</rdf:RDF>;
return myXML;
}
}
}
hello()
reside in separate namespaces, and, as such, each returns a different string when called.
package {
import flash.display.Sprite;
public class NamespaceExample extends Sprite {
public function NamespaceExample() {
var vocab:MultilingualVocabulary = new MultilingualVocabulary();
trace(vocab.hello()); // hello
var languages:Array = vocab.getLanguages();
for(var i:uint; i < languages.length; i++) {
var ns:Namespace = languages[i];
if(ns != null) {
trace(ns.uri + ": " + vocab.ns::hello());
// MultilingualVocabularyMultilingualVocabulary:Hawaiian: aloha
// MultilingualVocabularyMultilingualVocabulary:French: bon jour
}
}
}
}
}
class MultilingualVocabulary {
private namespace French;
private namespace Hawaiian;
private var languages:Array;
public function MultilingualVocabulary() {
languages = new Array(Hawaiian, French);
}
public function hello():String {
return "hello";
}
Hawaiian function hello():String {
return "aloha";
}
French function hello():String {
return "bon jour";
}
public function getLanguages():Array {
return languages;
}
}