tags:

views:

83

answers:

2
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/"  xmlns:jskit="http://purl.org/dc/elements/1.1/" >
    <channel>
        <title>www.domain.com/page_735.htm comments</title>
        <link>http://www.domain.com/page_735.html&lt;/link&gt;
        <atom:link rel="self" type="application/rss+xml" href="http://js-kit.com/rss/domain.com/page_735.html"&gt;&lt;/atom:link&gt;
        <jskit:attribute key="md5path" value="eb7110ce84f5907c29f0717c171ad35e"></jskit:attribute>
        <jskit:attribute key="path" value="/page_735.html"></jskit:attribute>
        <description>RSS comments feed for www.domain.com/page_735.html</description>
        <generator>JS-Kit Bulk Site Exporter 0.8</generator>
        <lastBuildDate>Mon, 09 Nov 2009 10:35:47 +0000</lastBuildDate>
        <item>
            <guid>jsid-1259747304-188</guid>
            <pubDate>Wed, 02 Dec 2009 09:48:24 +0000</pubDate>
            <jskit:attribute key="IP" value="59.182.xxx.xxx"></jskit:attribute>
            <jskit:attribute key="permalink" value="http://www.domain.com/page_735.html"&gt;&lt;/jskit:attribute&gt;
            <author>guest</author>
            <jskit:attribute key="share_facebook" value="off"></jskit:attribute>
            <jskit:attribute key="share_gfc" value="off"></jskit:attribute>
            <jskit:attribute key="share_twitter" value="off"></jskit:attribute>
            <jskit:attribute key="share_friendfeed" value="off"></jskit:attribute>
            <jskit:attribute key="share_yahoo" value="off"></jskit:attribute>
            <jskit:attribute key="Webpresence" value="[]"></jskit:attribute>
            <description>im a disco dancer</description>
            <jskit:parent-guid>jsid-1250154466-622</jskit:parent-guid>
        </item>
    </channel>
</rss>

I know a bit of xml but this one way beyond my imagination :(

How do i extract value of permalink or IP or parent-guid

I can only extract guid,pubdate ,author and description

I cant figure out namespaces

A: 

If you use a namespace-unaware parser, then you will just have some element names with colons in them. If you use a namespace-aware parser, you will have to specify the part after the colon and the URI defined for the part before the prefix when telling your API what element you are looking for.

e.g. jskit:attribute -> an element named 'attribute' in the namespace named '"http://purl.org/dc/elements/1.1/'.

bmargulies
did that now $item = $xml->channel[0]->item[0]; $jskitinfo = $item->children('http://purl.org/dc/elements/1.1/');But its returning me bunch of objects and cant loop thru them
vk123
Well, now you need help from someone who knows this particular PHP toolkit.
bmargulies
A: 

You will have to use XPath to find the right nodes, then get the value out of that. xpath() always returns an array, so you'll have to write a small function that returns only the first element of that array.

To access namespaced elements, you can either use an XPath expression or SimpleXML's children() method. Because "parent-guid" contains an hyphen, it makes writing the name of the property a bit awkward.

Here's a working example:

function attr(SimpleXMLElement $item, $key)
{
    $values = $item->xpath('./jskit:attribute[@key="' . $key . '"]/@value');
    return $values[0];
}

$rss = simplexml_load_string($xml);

foreach ($rss->channel->item as $item)
{
    $permalink   = attr($item, 'permalink');

    // either
    $parent_guid = $item->children('http://purl.org/dc/elements/1.1/')-&gt;{'parent-guid'};

    // or (PHP 5.2)
    $parent_guid = $item->children('jskit', true)->{'parent-guid'};

    // or
    $parent_guid = $item->xpath('./jskit:parent-guid');
    $parent_guid = $parent_guid[0];
}
Josh Davis