• Hello all!

    I’m currently trying to use PHP to display some XML data I have from a third party. We’re trying to display baseball information in a sortable table. Currently the code works but I need to know how to parse out and show only some of the data as opposed to all of it. Here’s one line from the XML:

    <Team LeagueId="1" league="AL" DivisionId="1" Div="East" TeamId="9" Abbr="NYA" CityName="New York" Nickname="Yankees" Wins="97" Losses="65" Rank="1" GamesBack="0.0" Wins10="5" Losses10="5" />

    For example, I’d like to only show all entries where DivisionId=”1″. Here’s the code I’m using, in full, to display the data:

    // load SimpleXML<br />
    $standings2011 = new SimpleXMLElement('standings_2011.xml', null, true);</p>
    <p>echo <<<EOF<br />
    <link rel="stylesheet" type="text/css" href="http://www.example.com/xmlstyle.css" /><br />
    <script src="http://www.example.com/sorttable.js"></script><br />
    <table class="xml sortable"><br />
            <tr><br />
                    <th>League</th><br />
                    <th>Team</th><br />
                    <th>Wins</th><br />
                    <th>Losses</th><br />
                    <th>Games Back</th><br />
            </tr><br />
    EOF;</p>
    <p>// loop through our books</p>
    <p>foreach($standings2011 as $Team) {<br />
            echo <<<EOF<br />
            <tr><br />
                    <td>{$Team['league']} {$Team['Div']}</td><br />
                    <td>{$Team['CityName']} {$Team['Nickname']}</td><br />
                    <td>{$Team['Wins']}</td><br />
                    <td>{$Team['Losses']}</td><br />
                    <td>{$Team['GamesBack']}</td><br />
            </tr></p>
    <p>EOF;<br />
    }<br />
    echo '</table>';

    Any help would be so great!

The topic ‘Using XML Schema in WordPress/PHP’ is closed to new replies.