Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8208825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:30:24+00:00 2026-06-07T09:30:24+00:00

I have the following feed which I wish to parse and grab certain data

  • 0

I have the following feed which I wish to parse and grab certain data from
http://xmlfeeds.centrebet.com/xmlRugbyLeaguefeed.xml

Whilst I was able to do this in past using a class to pull the XML into an array. I am suffering a few complications with it now, and there have been changes almost weekly that have made it hard to automate the grabbing as I was basing it on specific keywords.

What I want to grab from the XML is only the master events that have the attribute of
TopLevelName=”NRL Round 18″ (this will obviously change each week to round 19, 20 etc)

I then only need to get the following for each of the events under that masterevent

  • “straight bet” “price” for each “Competitor/competitorname”
  • EventURL
  • competitorname

I ave scrapped my code as it was overly complex but can paste it if you like, I was using this XML parser
http://www.bin-co.com/php/scripts/xml2array/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T09:30:26+00:00Added an answer on June 7, 2026 at 9:30 am

    You can do this very easy with SimpleXML, XPath, and for-each loops.

    There are only a few things to keep in mind with SimpleXML objects:

    • Each element becomes a SimpleXMLElement
    • Access the attributes of a SimpleXMLElement with array-notation (e.g., Element['attributeName'])
    • Access child elements of a certain name with object-notation (e.g., Element->ChildElements or Element->{Child-Element-With-Strange-Name})
    • Always cast to a string to get the text value (e.g. (string) Element or (string) Element['attribute'])
    • For fancier queries, use the xpath method.
    • To access namespaced elements, use the children method’s first argument.

    In general, whenever you have data-structured (vs document-structured) XML of a moderate size, the path of least resistance is SimpleXML. If you have a very large document, use a combination of XMLReader to break the document up into chunks, and XMLReader::expand() to process those chunks using DOMDocument or SimpleXML.

    The following function will extract the data you want into a structured array:

    function extractDataFromFeed($feeduri) {
        $events = array();
    
        $sxe = simplexml_load_file($feeduri);
        $targetMasterEvents = $sxe->xpath('/EventData/MasterEvents[starts-with(./@TopLevelName, "NRL Round ")]');
        foreach ($targetMasterEvents as $targetMasterEvent) {
            foreach ($targetMasterEvent->Event as $targetEvent) {
                $event = array(
                    'EventUrl' => (string) $targetEvent['EventURL'],
                    'Competitors' => array(), // CompetitorName => StraightBetPrice,
                                              // (assumes 1 price per competitorname)
                );
    
                foreach ($targetEvent->Competitors as $targetCompetitor) {
                    $targetBets = $targetCompetitor->xpath('BetType[@BetTypeName="Straight Bet"]');
    
                    foreach ($targetBets as $targetBet) {
                        $event['Competitors'][(string) $targetCompetitor['CompetitorName']]
                            = (string) $targetBet['Price'];
                    }
                }
            }
    
            $events[] = $event;
        }
        return $events;
    }
    
    
    $FEED = 'http://xmlfeeds.centrebet.com/xmlRugbyLeaguefeed.xml';
    $events = extractDataFromFeed($FEED);
    
    var_export($events);
    

    From here it is a simple matter to insert this data into a database (code below is untested):

    function insertEvents($eventname, $events, PDO $pdo) {
        // Set exception mode (if not set already)
        $old_ERRMODE = $pdo->getAttribute(PDO::ATTR_ERRMODE);
        $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
        // create prepared statements
        $insertEvent = $pdo->prepare('INSERT INTO events (EventName, EventURL) VALUES (?,?)');
        $insertBet = $pdo->prepare('INSERT INTO bets (event_id, CompetitorName, Price) VALUES (?,?,?)');
    
        // bind statement parameters
        $insertEvent->bindValue(1, $eventName, PDO::PARAM_STR);
        $insertEvent->bindParam(2, $eventURL, PDO::PARAM_STR);
        $insertBet->bindParam(1, $event_id, PDO::PARAM_INT);
        $insertBet->bindParam(2, $competitorName, PDO::PARAM_STR);
        $insertBet->bindParam(3, $price);
    
        // loop through event array, executing inserts
        foreach($events as $event) {
            $eventUrl = $event['EventURL'];
            $insertEvent->execute();
            $event_id = $pdo->lastInsertId();
            foreach($event['Competitors'] as $competitorName => $price) {
                $insertBet->execute();
            }
        }
    
        // restore ERRMODE setting (won't be restored if exception is raised!)
        $pdo->setAttribute(PDO::ATTR_ERRMODE, $old_ERRMODE);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following jQuery (info from here http://www.threelas.com/2012/02/basic-blogger-json-feed-api.html ). the problem i am
I have a URL string in the following format. http://myserver.com/_layouts/feed.aspx?xsl=4&web=%2F&page=dda3fd10-c776-4d69-8c55-2f1c74b343e2&wp=476f174a-82df-4611-a3df-e13255d97533 I want to replace
I have the following code I use to simulate a live data feed which
I have the following function that retrieves an image from a twitter feed, the
I have following requirement, I have C#/.Net console application, which refers to 'System.Data.Sqlite.dll' 'System.Data.Sqlite.dll'
I have following piece of code which tries to load an XML file from
I have XML shaped like the following: <?xml version=1.0 encoding=UTF-8?> <feed xmlns=http://www.w3.org/2005/Atom xmlns:openSearch=http://a9.com/-/spec/opensearch/1.1/ xmlns:docs=http://schemas.google.com/docs/2007
I have a client that sends an xml feed which I parse using the
I have a class which parse an XML feed. In that class I have
i have a following feed from twitter and im making all links clickable and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.