RSS | Archive | Random | E-mail

About

Hi, I'm Christian Castelli, a 28 years old italian programmer located in Pisa (Italy). Here I post small snippets of code which can be useful in my work.

Links

Codepuzzling main site
Development site
ByteStrike italian blog
Follow me on Twitter

My Life Style

while(passion) {
  try {
    myLife.run();
  }catch(LifeExceptions) {  
    stronger++;
    continue;
   }
}

Following

3 June 09

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:

this is an example
  ...
If you want to modify 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);

Tags: xml php
Comments (View)
blog comments powered by Disqus
Themed by Hunson. Originally by Josh