Table of contentsAppendices |
B.2 Namespace Prefix LookupNamespace Prefix Lookup
The following describes in pseudo code the algorithm used in the
NOTE:
DOMString lookupPrefix(in DOMString namespaceURI)
{
if (namespaceURI has no value, i.e. namespaceURI is null or empty string) {
return null;
}
short type = this.getNodeType();
switch (type) {
case Node.ELEMENT_NODE:
{
return lookupNamespacePrefix(namespaceURI, this);
}
case Node.DOCUMENT_NODE:
{
return getDocumentElement().lookupNamespacePrefix(namespaceURI);
}
case Node.ENTITY_NODE :
case Node.NOTATION_NODE:
case Node.DOCUMENT_FRAGMENT_NODE:
case Node.DOCUMENT_TYPE_NODE:
return null; // type is unknown
case Node.ATTRIBUTE_NODE:
{
if ( Attr has an owner Element )
{
return ownerElement.lookupNamespacePrefix(namespaceURI);
}
return null;
}
default:
{
if (Node has an ancestor Element )
// EntityReferences may have to be skipped to get to it
{
return ancestor.lookupNamespacePrefix(namespaceURI);
}
return null;
}
}
}
DOMString lookupNamespacePrefix(DOMString namespaceURI, Element originalElement){
if ( Element has a namespace and Element's namespace == namespaceURI and
Element has a prefix and
originalElement.lookupNamespaceURI(Element's prefix) == namespaceURI)
{
return (Element's prefix);
}
if ( Element has attributes)
{
for ( all DOM Level 2 valid local namespace declaration attributes of Element )
{
if (Attr's prefix == "xmlns" and
Attr's value == namespaceURI and
originalElement.lookupNamespaceURI(Attr's localname) == namespaceURI)
{
return (Attr's localname);
}
}
}
if (Node has an ancestor Element )
// EntityReferences may have to be skipped to get to it
{
return ancestor.lookupNamespacePrefix(namespaceURI, originalElement);
}
return null;
}
|