I'm trying to get a short script working. Bascially, take an RSS 2.0 feed (specifically, one from a Trac bug tracking system) and use DOM to make an object of it, then use xpath to extract the one child that has the ticket ID of a specific value in it.
Here's what I've come up with, and I'm no genius at xpath, so the query is dead wrong.
$xml = new DOMDocument('1.0', 'utf8');
if(!@$xml->loadHTML($temp))
exit('Unable to load XML properly.');
$query = '///item[title::contains(self, "'.$ticketID.'")]';
$xpath = new DOMXpath($xml);
$items = $xpath->query($query);
foreach($items as $item)
{
$entries[] = array(
'link' => $item->previousSibling->previousSibling->nodeValue,
'guid' => $item->previousSibling->nodeValue,
'title' => $item->nodeValue,
'description' => $item->followingSibling->nodeValue,
'category' => $item->followingSibling->followingSibling->nodeValue,
'comments' => $item->followingSibling->followingSibling->followingSibling->nodeValue
);
}
Now, I can get the file contents fine, and create the document. One thing you may notice is that I'm using loadHTML instead of loadXML. If I use loadXML, I get some invalid characters in the XML. loadHTML won't break that.
Thanks for any help you can offer me. You can use the demo tickets XML RSS Feed to test it out on.
I know I need to look inside of the <title> child of every <item> until I find one that matches the basic format of: #TicketID: Ticket Title / Summary
Each <title> node will follow that format. I figure xpath is the way to go here. Any help would be appreciated.