|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2015-09-15 19:50 UTC] requinix@php.net
[2019-09-22 22:31 UTC] beberlei@php.net
-Status: Open
+Status: Wont fix
-Assigned To:
+Assigned To: beberlei
[2019-09-22 22:31 UTC] beberlei@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Nov 04 16:00:01 2025 UTC |
Description: ------------ Now if you want to use DOMDocument::createAttribute $domDocument = new DOMDocument('1.0', "UTF-8"); $domElement = $domDocument->createElement('field','some random data'); $domAttribute = $domDocument->createAttribute('name'); // Value for the created attribute $domAttribute->value = 'attributevalue'; // Don't forget to append it to the element $domElement->appendChild($domAttribute); // Append it to the document itself $domDocument->appendChild($domElement); What I am suggesting is because DOMDocument::createAttribute returns a new instance of class DOMAttr. And the DOMAttr class contructor accepts as params the name and the value of the attribute, so I suggest that createAttribute also accepts value as a param $domDocument = new DOMDocument('1.0', "UTF-8"); $domElement = $domDocument->createElement('field','some random data'); // Create and set value for the attribute $domAttribute = $domDocument->createAttribute('name', 'attributevalue'); // Don't forget to append it to the element $domElement->appendChild($domAttribute); // Append it to the document itself $domDocument->appendChild($domElement); --- Because this is possible $domDocument = new DOMDocument('1.0', "UTF-8"); $domElement = $domDocument->createElement('field','some random data'); // Create and set value for the attribute // Using the DOMAttr directly $domAttribute = new \DOMAttr('name', 'attributevalue'); // Don't forget to append it to the element $domElement->appendChild($domAttribute); // Append it to the document itself $domDocument->appendChild($domElement);