Re: Return XML attribute in DOM
Re: Return XML attribute in DOM
am 07.09.2009 17:43:15 von Ashley Sheridan
On Mon, 2009-09-07 at 16:37 +0100, Matthew Croud wrote:
>
> I'm at my wits end here, so close to the finishing line!
>
> Is there a method to return an attribute value of an XML node using
> DOM, I can check to see if an attribute exists using hasAttributes()
> But I can't retrieve the value.
>
> I'm so desperate i've started to eat dirt.
>
> Many thanks,
> Matt
Doesn't the DOM have the getAttribute() method?
Thanks,
Ash
http://www.ashleysheridan.co.uk
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Return XML attribute in DOM
am 07.09.2009 17:51:05 von Matthew Croud
>> 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("
");
foreach ($topics as $node )
{
echo("- ". $node -> hasAttributes() ."
");
}
echo("
");
______________________________
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 ?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Return XML attribute in DOM
am 08.09.2009 10:08:06 von Peter Ford
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("
");
> foreach ($topics as $node )
> {
> echo("- ". $node -> hasAttributes() ."
");
> }
> echo("
");
>
> ______________________________
>
> 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-attribu te.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
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Return XML attribute in DOM
am 08.09.2009 13:06:30 von Matthew Croud
--Apple-Mail-12--777115848
Content-Type: text/plain;
charset=US-ASCII;
format=flowed;
delsp=yes
Content-Transfer-Encoding: 7bit
Cheers Guys,
Your the greatest !
On 8 Sep 2009, at 09:08, Peter Ford wrote:
> 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("
");
>> foreach ($topics as $node )
>> {
>> echo("- ". $node -> hasAttributes() ."
");
>> }
>> echo("
");
>>
>> ______________________________
>>
>> 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-attribu te.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
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
Matthew Croud
Studio
Obvious Print Solutions Limited
Unit 3 Abbeygate Court
Stockett Lane
Maidstone
Kent
ME15 0PP
T | 0845 094 9704
F | 0845 094 9705
www.obviousprint.com
--Apple-Mail-12--777115848--