Re: [DOM] DOM4 draft : getAttributeNode() and getAttributeNodeNS() substitute ?

 >Why not store this information on the Element object instead?

Imagine you want to add some properties on attributes :

let attr1 = element.getAttributeNode("myAttr1");
attr1.matchScore = 32;
attr1.isTitle = true;

let attr2 = element.getAttributeNodeNS("myNs", "myAttr2");
attr2.isLink = true;
attr2.targetNode = otherNode;


And later :

if(element.getAttributeNode("myAttr1").isTitle) ...


If you don't use the Attr object benefits, you have to implement your 
own properties list on the element :

element.myAttrProps = [];

let attr1 = {};
attr1.nodeName = "myAttr1";
attr1.matchScore = 32;
attr1.isTitle = true;
element.myAttrProps .push(attr1);

let attr2 = {};
attr1.nodeName = "n:myAttr2";
attr1.ns = "myNs";
attr1.localName = "myAttr2";
attr2.isLink = true;
attr2.targetNode = otherNode;
element.myAttrProps .push(attr2);


And you need to add your own methods to find your attrProps by nodeName 
and by ns+localName.
Of course it is always possible but it's not user friendly and probably 
more costly.

-----
An other example : you simply want to know the prefix used for an 
attribute. Without getAttributeNodeNS(), you have to iterate on the 
attributes array in order to find the Attr and then get the prefix... 
Not easy !

-----
I don't understand the current approach. I think there are two points of 
view :
1 - We completely remove the Attr class, and attribute values are only 
accessible as properties on the element node.
2 - We have an Attr class and we give unfettered access to these objects 
(not half).

With the current draft, we are in midstream.

In my opinion, the first point of view is not a good OO design, and I 
think it is interesting to be able to handle an Attr object (and I'm ok 
that Attr class should not extend Node).

Received on Friday, 5 October 2012 08:12:41 UTC