Jump to content

Which is best (element or attribute)?


Recommended Posts

As I told you in the PM you sent me, performance with DOM can vary from one implementation to another, and also vary depending on the method used, so no answer is truly final.If you're parsing XML on the cliet side (i.e. with JavaScript) your best bet is to use attributes. The reason is not performance, but rather file size. Consider:



<a b="content" c="content" d="content" e="content" f="content" g="content"/>

Clients will download the later faster the former. How fast it's traversed is another story, but if the file is downloaded quickly enough, this is still a performance increase, as the traversing will start sooner.The best way to test which is better is to simply make some test with your environment. How exactly... I don't know for sure. I'm not much of a DOM user myself, but in any case, you'll need to make one very large document with lots of similar elements, another with lots of different element, a third one with lots of same attributes on different elements, and another with lots of different attributes on a single element. Then of course, try to traverse each tree, do something on each match of it and (this is the hardest part for me) display the time of the complete process.

Link to comment
Share on other sites

Hi, while you are parsing with DOM, its doesn't matter you use element or attribute.its all depend on nature of your task.attribute is nothing but property of your node, sometime we access attribute to identify the set of nodes or node, and sometimes to get the value of attribute all depend what you want.So, I don't think so question should be arise which should be used.This is what I got from you question.Regards,Ashvini

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...