1

I am trying to get information from a RSS feed, and it I have managed to what I want using PHP and Jquery, but I want to cron it, and at the moment my app starts using .js, which my host says cannot be started with cron.

If I use SimpleXML_load_file, it brings with it everything, accept the attributes within <item>....</item> and a child <a10:updated>

Here is a section of raw feed:

SimpleXMLElement Object ( [@attributes] => Array ( [version] => 2.0 )

[channel] => SimpleXMLElement Object
    (
        [title] => Bills from current Parliamentary Session
        [link] => http://services.parliament.uk/bills
        [description] => SimpleXMLElement Object
            (
            )

        [item] => Array
            (
                [0] => SimpleXMLElement Object
                    (
                        [guid] => http://services.parliament.uk/bills/2013-14/finance.html
                        [link] => http://services.parliament.uk/bills/2013-14/finance.html
                        [category] => Array
                            (
                                [0] => Commons
                                [1] => Government Bill
                            )

                        [title] => Finance
                        [description] => A Bill To grant certain duties, to alter other duties, and to amend the law relating to the National Debt and the Public Revenue, and to make further provision in connection with finance.
                    )

                [1] => SimpleXMLElement Object
                    (
                        [guid] => http://services.parliament.uk/bills/2013-14/humberbridge.html
                        [link] => http://services.parliament.uk/bills/2013-14/humberbridge.html
                        [category] => Array
                            (
                                [0] => Lords
                                [1] => Private Bill
                            )

                        [title] => Humber Bridge
                        [description] => A Bill to amend the constitution of the Humber Bridge Board and to confer new borrowing and other powers on it; to make new provision for the recovery of any deficit of the Board from local authorities in the area; to confer new powers for the setting and revision of tolls and to make other provision for and in connection with the operation of the bridge; and for connected purposes.
                    )

And here is the rss feed: http://services.parliament.uk/bills/AllBills.rss

Is there another way to get raw rss that adds all ?

hakre
  • 193,403
  • 52
  • 435
  • 836
Andrew Walker
  • 492
  • 1
  • 5
  • 23
  • possible duplicate of [Parse XML with Namespace using SimpleXML](http://stackoverflow.com/questions/595946/parse-xml-with-namespace-using-simplexml) - Please use the search before asking your question. See as well the related column on the right, e.g. [php's simplexml_load_file() not loading all keys](http://stackoverflow.com/questions/3622715/phps-simplexml-load-file-not-loading-all-keys) – hakre Jun 07 '13 at 11:25
  • [duplicate? .](http://stackoverflow.com/a/6534234/3100494) – J-Dizzle Apr 23 '14 at 18:21

1 Answers1

2

The use of print_r() on SimpleXML objects is unreliable. It doesn't always show the full structure.

Your <a10:updated> element uses XML Namspaces, which require special treatment. Here's an example of how to access it:

$obj = simplexml_load_file(....);
foreach($obj->channel->item as $item)
{
    echo $item->children('http://www.w3.org/2005/Atom')->updated;
}

As you can see, you have to pass the value of the a10 namespace to children(). The namespace definition can be found at the top of the XML:

xmlns:a10="http://www.w3.org/2005/Atom"

MrCode
  • 63,975
  • 10
  • 90
  • 112
  • that makes sense and works, so thank you for that. But I am still unable to find `` which is within the ` – Andrew Walker Jun 07 '13 at 11:17
  • Would it be better to make into a DOMDocument, as I have seen a few examples of that, and then use the `getAttribute` ? – Andrew Walker Jun 07 '13 at 11:38
  • 1
    For the attribute namespaces, just do the same as with `children()` e.g. `$item->attributes('nameapace here')->stage`, look in the XML to see what the `p4` nameapce is. – MrCode Jun 07 '13 at 11:46