0

I'm working with this XML file that has some empty attributes, in which case I want to skip that entire attribute's list item. Unfortunately my code still shows everything, even if one of the attributes are empty. I'm sure there's a simpler (and working) way to do this. Here's my page and code:

$file = 'http://www.gostanford.com/*****/data/xml/events/m-baskbl/2010/index.xml';
$xml = simplexml_load_file($file);

foreach($xml as $event_date){
    if(isset($event_date->event['vn']) && isset($event_date->event['hn']) && isset($event_date->event['vs']) && isset($event_date->event['hs']))
    { 
        echo '<li>';
        echo '<h3>', $event_date->event['vn'], ' vs ', $event_date->event['hn'], '</h3>';
        echo '<p><strong>', $event_date->event['local_time'], '</strong></p>';
        echo '<h3>', $event_date->event['vs'], ' - ', $event_date->event['hs'], '</h3>';
        echo '</li>';   
    }
}

1 Answer 1

3

Replace your isset with !empty

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

4 Comments

I discovered one problem with this. If either team was shutout, i.e. scored a "0", the entire score is excluded. How can this be edited to include zeros? isset won't work, as it includes empty results, which I definitely want to avoid.
@Ryan: well, you need to use compose condition with isset and strlen as @mario proposed :-S
I'm not sure how to do that and don't see @mario's response. Do you know how I can do this? Thank you :)
@Ryan: isset($var) && strlen($var)

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.