Flash CS3 Documentation |
|||
| ActionScript 2.0 Language Reference > ActionScript classes > XMLNode > getPrefixForNamespace (XMLNode.getPrefixForNamespace method) | |||
public getPrefixForNamespace(nsURI:String) : String
Returns the prefix that is associated with the specified namespace URI for the node. To determine the prefix, getPrefixForNamespace() searches up the XML hierarchy from the node, as necessary, and returns the prefix of the first xmlns declaration with a namespace URI that matches nsURI.
If there is no xmlns assignment for the given URI, the method returns null. If there is an xmlns assignment for the given URI but no prefix is associated with the assignment, the method returns an empty string ("").
Availability: ActionScript 1.0; Flash Player 8
nsURI:String - The namespace URI for which the method returns the associated prefix.
String - The prefix associated with the specified namespace.
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():XMLNode {
var str:String = "<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:XMLNode = createXML();
trace(xmlDoc.getPrefixForNamespace("http://www.example.com/util")); // output: exu
trace(xmlDoc.getPrefixForNamespace("http://www.example.com/other")); // output: null
var child1:XMLNode = xmlDoc.firstChild;
trace(child1.getPrefixForNamespace("http://www.example.com/child")); // output: [empty string]
trace(child1.getPrefixForNamespace("http://www.example.com/other")); // output: null
getNamespaceForPrefix (XMLNode.getNamespaceForPrefix method), namespaceURI (XMLNode.namespaceURI property)
Flash CS3
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/9.0/main/00002351.html