Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Whats the difference between setAttribute & setAttributeNode?

Tags:

dom

php

I'm playing around with PHP's DOMDocument at the moment. As the question states, what are the differences between these two methods (other than needing to pas a DOMAttr to setAttributeNode) and in what situations should each be used?

like image 324
hellsgate Avatar asked Jul 27 '12 10:07

hellsgate


1 Answers

As I recall, there's not a lot in it. The main difference, other than the one you've identified, is setAttributeNode cannot be used to simultaneously set a value for the attribute, only its name.

In effect, it's a means of preparing an attribute, off the DOM, for insertion at a later point.

setAttribute is a quicker means of doing this; it allows the stipulation of both the name and value.

like image 99
Mitya Avatar answered Oct 23 '22 05:10

Mitya