Posted by Toby A Inkster on 08/06/07 20:24
php.developer2007 wrote:
> Hi i want to parse a xml document which contains attribute can anybody
> help me in that.
http://www.php.net/dom
> I want to get all id's in this example with using regular
> expressions..
<?php
$xml = '<?xml version="1.0"?>
<categories>
<category id="1" parent-id="1" level="2"/>
<category id="2" parent-id="1" level="3"/>
<category id="3" parent-id="5" level="6"/>
</categories>';
$document = new DomDocument;
$document->loadXML($xml);
$id_list = array();
foreach ($document->getElementsByTagName('category') as $category)
$id_list[] = $category->getAttribute('id');
print_r($id_list);
?>
--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 46 days, 23:56.]
Command Line Interfaces, Again
http://tobyinkster.co.uk/blog/2007/08/02/command-line-again/
Navigation:
[Reply to this message]
|