by prettyscripts on 2007-12-14 01:11:22
in php5, parsing and processing xml can be easily done with SimpleXML extension.
to parse xml file:
PHP:
$obj = simplexml_load_file($file); |
to parse xml string:
PHP:
$obj = simplexml_load_string($string); |
XML:
<data> | |
<tag>value 1<tag> | |
<tag attribute="attrbute value">value 2<tag> | |
</data> |
after loading xml into $obj, access tag values as class method:
PHP:
$obj->tag | |
$obj->tag[i] //if more than 1 tag |
access tag attribute as array:
PHP:
$obj->tag['attribute'] | |
$obj->tag[i]['attribute'] // if more than 1 tag |