Re: Return XML attribute in DOM
| From: | Peter Ford | Date: | Tue, 08 Sep 2009 08:08:06 +0000 |
| Subject: | Re: Return XML attribute in DOM | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-297786@lists.php.net to get a copy of this message | ||
Matthew Croud wrote:
>>> Doesn't the DOM have the getAttribute() method?
>>
>> Thanks,
>> Ash
>> http://www.ashleysheridan.co.uk
>
> It's not in my reference, though I see it in the PHP manual now.
> This is what I have:
>
> _____________________________
>
> $dom = new DomDocument();
> $dom -> load("items.xml");
>
> $topics = $dom -> getElementsByTagName("item");
>
> echo("<ul>");
> foreach ($topics as $node )
> {
> echo("<li>". $node -> hasAttributes() ."</li>");
> }
> echo("</ul>");
>
> ______________________________
>
> I'm replacing hasAttributes() with getAttribute() but its throwing me an
> error, I'm probably using it incorrectly.
> I think I'm drowning in the deep end =/
> Could you advise Gamesmaster ?
It's a method on DomElement:
http://uk3.php.net/manual/en/function.domelement-get-attribute.php
and you need to tell it which attribute to get... :)
--
Peter Ford phone: 01580 893333
Developer fax: 01580 893399
Justcroft International Ltd., Staplehurst, Kent