note 102052 modified in simplexmlelement.asxml by danbrown
| From: | danbrown@php.net | Date: | Tue, 25 Jan 2011 13:59:00 +0000 |
| Subject: | note 102052 modified in simplexmlelement.asxml by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-176294@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:
<?php
$document = simplexml_load_file("mydoc.xml");
$cont = (integer) $document['counter'];
$document['counter'] = $cont+1;
$document->asXML("mydoc.xml");
?>
--was--
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");
http://php.net/manual/en/simplexmlelement.asxml.php