note 102052 added to simplexmlelement.asxml
| From: | jcr at di dot uminho dot pt | Date: | Tue, 25 Jan 2011 10:32:40 +0000 |
| Subject: | note 102052 added to simplexmlelement.asxml | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-176279@lists.php.net to get a copy of this message | ||
Code snippet to load a XML document, increment an attribute and store it again.
My XML looks like:
<?xml version="1.0" encoding="ISO-8859-1"?>
<doctypes counter="16">
<doctype id="d1">
<name>Carta</name>
<acro>CA</acro>
</doctype>
...
</doctypes>
I want to retrieve the counter attribute, increment it, and store the new document at the end:
$document = simplexml_load_file("mydoc.xml");
$cont = (integer) $document['counter'];
$document['counter'] = $cont+1;
$document->asXML("mydoc.xml");
----
Server IP: 69.147.83.197
Probable Submitter: 85.139.249.20
----
Manual Page -- http://www.php.net/manual/en/simplexmlelement.asxml.php
Edit -- https://master.php.net/note/edit/102052
Del: integrated -- https://master.php.net/note/delete/102052/integrated
Del: useless -- https://master.php.net/note/delete/102052/useless
Del: bad code -- https://master.php.net/note/delete/102052/bad+code
Del: spam -- https://master.php.net/note/delete/102052/spam
Del: non-english -- https://master.php.net/note/delete/102052/non-english
Del: in docs -- https://master.php.net/note/delete/102052/in+docs
Del: other reasons-- https://master.php.net/note/delete/102052
Reject -- https://master.php.net/note/reject/102052
Search -- https://master.php.net/manage/user-notes.php