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 ?

2

1 Answer 1

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"

Sign up to request clarification or add additional context in comments.

3 Comments

that makes sense and works, so thank you for that. But I am still unable to find <p4:stage> which is within the <item.... tag. This is an attribute of the item tag, how would I get inside that ?
Would it be better to make into a DOMDocument, as I have seen a few examples of that, and then use the getAttribute ?
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.