开发者

simplexml_load_file() with non-standard XML file

开发者 https://www.devze.com 2023-03-04 04:08 出处:网络
I\'m having trouble using a non-standard XML file with simplexml_load_file(). Here\'s my code: <?php

I'm having trouble using a non-standard XML file with simplexml_load_file(). Here's my code:

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

echo 'Displaying user names of XML file...<br />';
foreach($xml as $event_dat开发者_如何学运维e){
    echo 'Home: '.$event_date->hn.'<br />';
}

?>

As you'll see, nothing is being output from the XML file, only the echo'd "Home:"

Any help is greatly appreciated.


This is the XML data, nothing non-standard about it:

<game_days>
   <event_date date="20101023">
      <event id="1271699" local_time="6:00 PM PT" eastern_time="21:00" hc="stan" vc="" hn="Stanford" vn="" hs="" vs=""/>
   </event_date>

The attribute you are looking for is one element level <event> below.
And to access attributes use the array syntax instead:

foreach($xml as $event_date){
    echo $event_date->event['hn'];


If by non-standard you mean a different namespace here is what you can do:

Namespaces

you can get the namespace and work with it like a "standard xml"

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号