Browse files

Apply namespaces to attributes immediately.

Namespace declarations take effect immediately in XML affecting the
current element and attributes. The current implementation did not
appear to apply namespaces to the attributes belonging to the same
element in which the namespace was declared.

Upon inspecting the code, the loop that is supposed to perform this
assignment does not actually loop through the attribute array. It
increments a index, but it does update the local variable used to
reference the attribute in the attribute list at the index.

With this commit, the local variable is updated. A test has been added
to the DOM attributes test suite to ensure that namespaces are applied
to attributes immediately.
  • Loading branch information...
1 parent 063add7 commit dc0ecd772673dc4d1d0c746154002620bd01c8f4 @bigeasy bigeasy committed Jun 18, 2012
Showing with 5 additions and 0 deletions.
  1. +1 −0 sax.js
  2. +4 −0 test/dom/attr.js
1 sax.js
@@ -278,6 +278,7 @@ function appendElement(contentHandler,elStack,el,tagName,selfClosed){
var i = el.length;
+ a = el[i];
var prefix = a.prefix;
if(prefix){//no prefix attribute has no namespace
if(prefix === 'xml'){
@@ -31,6 +31,10 @@ wows.describe('XML attrs').addBatch({
// root.firstChild.setAttributeNode(root.attributes[0]);
// console.assert(root.attributes.length == 0);
+ "attribute namespace":function(){
+ var root = new DOMParser().parseFromString("<xml xmlns:a='a' xmlns:b='b' a:b='e'></xml>",'text/xml').documentElement;
+ console.assert(root.getAttributeNS("a", "b"), "e");
+ },
"override ns attribute":function(){

0 comments on commit dc0ecd7

Please sign in to comment.