Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,9 @@ Node.prototype = {
},
lookupPrefix:function(namespaceURI){
var el = this;
if(el.nodeType == DOCUMENT_NODE){
el = el.documentElement;
}
while(el){
var map = el._nsMap;
//console.dir(map)
Expand All @@ -378,13 +381,16 @@ Node.prototype = {
}
}
}
el = el.nodeType == ATTRIBUTE_NODE?el.ownerDocument : el.parentNode;
el = el.nodeType == ATTRIBUTE_NODE?el.ownerElement : el.parentNode;
}
return null;
},
// Introduced in DOM Level 3:
lookupNamespaceURI:function(prefix){
var el = this;
if(el.nodeType == DOCUMENT_NODE){
el = el.documentElement;
}
while(el){
var map = el._nsMap;
//console.dir(map)
Expand All @@ -393,7 +399,7 @@ Node.prototype = {
return map[prefix] ;
}
}
el = el.nodeType == ATTRIBUTE_NODE?el.ownerDocument : el.parentNode;
el = el.nodeType == ATTRIBUTE_NODE?el.ownerElement : el.parentNode;
}
return null;
},
Expand Down
10 changes: 9 additions & 1 deletion test/parse/namespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,13 @@ wows.describe('XML Namespace Parse').addBatch({
console.assert(root.firstChild.namespaceURI=='http://p.com')
console.assert(root.lastChild.namespaceURI=='http://test.com')
console.assert(root.firstChild.nextSibling.lookupNamespaceURI('p') == 'http://test.com')
},
'performing a lookup from a document node': function () {
var documentNode = new DOMParser().parseFromString('<xml xmlns="http://test.com"/>','text/xml');
console.assert(documentNode.lookupNamespaceURI('') == 'http://test.com')
},
'performing a lookup from an attribute node': function () {
var documentNode = new DOMParser().parseFromString('<xml xmlns="http://test.com" attr="1"/>','text/xml');
console.assert(documentNode.documentElement.getAttributeNode('attr').lookupNamespaceURI('') == 'http://test.com')
}
}).run(); // Run it
}).run(); // Run it