kapitanluffy
kapitanluffy

Reputation: 1267

PHP retrieving XML tagnames

i am actually new with these XML stuff. I do understand things about the DOMDocument,DOMNOdeList and etc using http://www.php.net/manual/en/intro.dom.php

so here is the problem..

http://jobhits.co.uk/services/rss?k=job

the feed above returns an XML document. i can successfully retrieve tag names like title,description and link using these codes

$doc->load('http://jobhits.co.uk/services/rss?k=job');
$items = $doc->getElementsByTagName("item");

foreach($items as $item){
    $titles[] = $item->getElementsByTagName("title");
}

the problem is there is a certain 'tagname-like' in that document

<a10:updated></a10:updated>

i tried getting that using

$update[] = $item->getElementsByTagName("a10:updated");

..which is a failure

here is a sample xml http://piratelufi.com/ark/gettagname.xml or you can use the string inside load method above :)

btw i can't use simpleXML and predefined classes as much as possible thanks :D

Upvotes: 1

Views: 369

Answers (2)

Dilettant
Dilettant

Reputation: 3345

The a10 jsut denotes, that the element updated is from a different namespace. The colon : is a special character in this context. In the beginning of your sample xml (the latter url) one finds the definition of this namespace: <rss xmlns:a10="http://www.w3.org/2005/Atom" version="2.0">. So You need getElementsByTagNameNS. I presume something along the lines of: getElementsByTagNameNS("http://www.w3.org/2005/Atom","updated")might help.

Upvotes: 2

Wrikken
Wrikken

Reputation: 70540

You are looking for getElementsByTagNameNS,

Upvotes: 2

Related Questions