How to read/write root’s attributes in SimpleXMLElement
If you use SimpleXMLElement to read and write your XML documents, this trick is useful to read/write root element attributes. Suppose to have such a document:
If you want to modify... this is an example
count or uniqueCount in PHP, you only need to do this:
try{
// load the file
$xml = simplexml_load_file($this->xl_sharedStrings);
} catch(Exception $e) {
die("
Cannot parse file: ".$e->getMessage());
}
$xml['count'] = $count;
$xml['uniqueCount'] = $unique;
$xml->asXML($this->xl_sharedStrings);