note 74936 rejected from function.domdocument-create-attribute by nlopess
| From: | nlopess@php.net | Date: | Sat, 12 May 2007 11:36:48 +0000 |
| Subject: | note 74936 rejected from function.domdocument-create-attribute by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-126455@lists.php.net to get a copy of this message | ||
Note Submitter: rlee0001 at sbcglobal dot net
----
The manual (and/or DOM XML API) is inconsistent and incorrect here (or at least misleading).
This article states that:
"This node will not show up in the document unless it is inserted with e.g.
domnode_append_child()."
While the article for domnode_append_child() states that:
"Note: You can not append a DOMAttribute using this method. Use DomElement->set_attribute()
instead."
I guess the confusing bit is that this article starts talking about "this node". What
node? This article isn't about nodes, but rather attributes. And the article for
domnode_append_child() indicates that domelement_set_attribute() should be used to insert a
DOMAttribute, but in fact domelement_set_attribute won't accept a DOMAttribute object as input,
but rather a string name and string value. This brings us right back to square one.
So I have the following rhetorical questions (and answers):
When you create a DOMAttribute object using this method, is the DomDocument modified directly? No, a
new orphaned DOMAttribute object is simply returned.
Is there a domelement_append_attribute() method (or some equivalent) that can be used to attach the
DOMAttribute object to a DomElement? No, the DOMAttribute object cannot be attached to any
DomElement. Note: domelement_set_attribute() can be used to add an attribute to a DOMElement.
Will domelement_set_attribute() accept the DOMAttribute object as a parameter? No, is accepts the
same parameters this method does (string name and string value).
So what is the purpose of the returned DOMAttribute object? The returned DOMAttribute object is
completely useless.
So what is the purpose of this method? This method is completely useless.
So now I have a non-rhetorical question:
Why does the DOM XML API have methods that return useless objects? Or maybe a bigger question: why
does PHP have both a DOM XML API and a DOM API, both of which operate on XML DOMs?
-Robert