|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-07-22 04:39 UTC] jeremybotto at gmail dot com
Description: ------------ --- From manual page: http://www.php.net/simplexmlelement.addattribute%23Examples --- The sample code depends upon the inclusion of example code, example.php, from an earlier page. Without example.php, the sample code does not work. Running the sample code outputs the the input. There is no visible change on inspection of the files, directories, and source code. I tried stripping parts of example.php out, to see if the code sample actually added any attributes, and the sample code just throws errors when lines are removed. Basically, the code does nothing to 'manipulate' XML. It simply verifies that a translation of the input matches the input. Can we get an example that doesn't depend upon external files and that actually changes something, please? Expected result: ---------------- Add an attribute to an XML file via PHP. Actual result: -------------- Does nothing. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 07 07:00:01 2026 UTC |
All pages including 'example.php' note that it is a file containing an XML string, and that it can be found on the basic usage page, and they link to the basic usage page. I think you're misunderstanding how SimpleXMLElement::addAttribute works. In the description, it states "Adds an attribute to the SimpleXML element." addAttribute doesn't modify any file, it modifies the SimpleXMLElement object. If you wish to output the XML represented by a SimpleXMLElement object, you can use the SimpleXMLElement::asXML() method, as is done in the examples. If you look at the XML output in the example versus the original string in example.php, you'll see that attributes were indeed added. If you want to write to a file, you could do something like file_put_contents('my_xml_file.xml', $sxe->asXML());