
ADOBE FLASH MEDIA INTERACTIVE SERVER
Server-Side ActionScript Language Reference
126
Parameters
nsURI A string; the namespace URI for which the method returns the associated prefix.
Returns
A string.
Example
The following example creates a very simple XML object and outputs the result of a call to the
getPrefixForNamespace() method. The Outer XML node, which is represented by the xmlDoc variable, defines
a namespace URI and assigns it to the
exu prefix. Calling the getPrefixForNamespace() method with the defined
namespace URI ("http://www.example.com/util") returns the prefix
exu, but calling this method with an undefined
URI ("http://www.example.com/other") returns
null. The first exu:Child node, which is represented by the
child1 variable, also defines a namespace URI ("http://www.example.com/child"), but does not assign it to a prefix.
Calling this method on the defined, but unassigned, namespace URI returns an empty string.
function createXML() {
var str = "<Outer xmlns:exu=\"http://www.example.com/util\">"
+ "<exu:Child id='1' xmlns=\"http://www.example.com/child\"/>"
+ "<exu:Child id='2' />"
+ "<exu:Child id='3' />"
+ "</Outer>";
return new XML(str).firstChild;
}
var xmlDoc = createXML();
trace(xmlDoc.getPrefixForNamespace("http://www.example.com/util")); // output: exu
trace(xmlDoc.getPrefixForNamespace("http://www.example.com/other")); // output: null
var child1 = xmlDoc.firstChild;
trace(child1.getPrefixForNamespace("http://www.example.com/child")); // output: [empty
string]
trace(child1.getPrefixForNamespace("http://www.example.com/other")); // output: null
See also
XML.getNamespaceForPrefix()
XML.hasChildNodes()
my_xml.hasChildNodes()
Returns true if the specified XML object has child nodes; otherwise, false.
Availability
Flash Media Server 2
Returns
A boolean value.
Example
The following example creates a new XML packet. If the root node has child nodes, the code loops over each child
node to display the name and value of the node.
var my_xml = new
XML("<login><username>hank</username><password>rudolph</password></login>");
if (my_xml.firstChild.hasChildNodes()) {
// Use firstChild to iterate through the child nodes of rootNode.
Commenti su questo manuale