Doc #55264 [Fbk->Opn]: Example does nothing

From: Date: Wed, 27 Jul 2011 16:42:12 +0000
Subject: Doc #55264 [Fbk->Opn]: Example does nothing
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-6936@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=55264&edit=1 ID: 55264 User updated by: jeremybotto at gmail dot com Reported by: jeremybotto at gmail dot com Summary: Example does nothing -Status: Feedback +Status: Open Type: Documentation Problem Package: Documentation problem Operating System: php PHP Version: Irrelevant Block user comment: N Private report: N New Comment: The recommendations I receive from PHP developers is to not use SimpleXML because it is too difficult and complicated. Instead, use domdocument, which is also complicated. Also, don't use the php manual to learn it. I'm sure that you are already well aware of the flaws in the documentation. I seriously doubt anyone is going to take action. However, I'll entertain you, against my will and better judgment: 1) Include xml files, not php files, in the examples. 2) Use all of the parameters and switches in at least one example. 3) Use xml for the output unless another output format is specified, in which case, use xml output and the specified output where applicable. Previous Comments: ------------------------------------------------------------------------ [2011-07-27 13:47:22] salathe@php.net Your comments make no sense in the context of a documentation bug report. If you feel something is missing from the documentation, or something documented is incorrect, please outline what you want to see changed. ------------------------------------------------------------------------ [2011-07-27 12:31:05] jeremybotto at gmail dot com That doesn't help at all. The output is in php, even though I use asXML();, and it doesn't change the file. It just changes the source code of the page. All of the examples change one file and output to the same file, and that doesn't leave any room for version control. Also, at http://www.php.net/manual/en/simplexml.examples-basic.php, if you look at the examples, they all output in plain text for this same reason. This doesn't say anything about how the nesting is manipulated by SimpleXML, which is crucial to understanding SimpleXML and makes the manual impossible to understand. Look at a specific example: <?php include 'example.php'; $xml = new SimpleXMLElement($xmlstr); foreach ($xml->xpath('//character') as $character) { echo $character->name, 'played by ', $character->actor, PHP_EOL; } ?> '//' serves as a wildcard. To specify absolute paths, omit one of the slashes. The above example will output: Ms. Coder played by Onlivia Actora Mr. Coder played by El ActÓr Fortunately for us, they've followed the example of php.net and not included the XML file, so we can't tell what they're manipulating, but it looks like this: <characters><character><name>text</name><actor>text</actor></character>. The output doesn't include the element nodes, so there's no way to tell if they have been stripped, if new ones have been added, or just what. Because the document doesn't actually come across as XML, it appears that SimpleXML acts to convert XML into plain text, but everyone knows that isn't its intended use. It's supposed to allow people to manipulate XML. So, it should give XML output from XML input unless otherwise specified, rather than giving raw text. ------------------------------------------------------------------------ [2011-07-22 04:52:23] salathe@php.net Can you clarify a few things, please? When you say "there is no visible change", where did you expect anything to be changed (the example should print the manipulated XML to the screen, terminal, wherever)? What do you mean by "verifies that a translation of the input matches the input", there is no translation of any kind going on. For what it's worth, here's an include-less version of that example showing the expected output: http://codepad.org/gwx8oJpw Finally, with regards to the SimpleXML examples requiring the example.php file, this was done to avoid clogging up the examples with 28 lines of code again and again. Requiring external files is not something we usually ask for examples, which should be able to run "standalone" ideally. ------------------------------------------------------------------------ [2011-07-22 04:39:31] 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. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=55264&edit=1

« previous php.doc.bugs (#6936) next »