我需要实现一个PHP文件从目录中读取x文件,每次更新我的db表。更新没有问题,但是,我不是最好的xml在php。这是xml文件:
<SeasonStatistics competition_name="Italian Serie A" season_name="Season 2015/2016" season_id="2015" competition_id="21">
<Team name="Roma" id="121"><Stat name="Total Shots">102</Stat>
<Stat name="Possession Percentage">64</Stat><Stat name="Total Fouls Won">93</Stat>
<Stat name="Unsuccessful Dribbles">60</Stat>
<Stat name="PutThrough/Blocked Distribution">125</Stat>
<Stat name="Goals">17</Stat>
<Stat name="Headed Goals">2</Stat>
<Stat name="Unsuccessful lay-offs">5</Stat>
<Stat name="Total Passes">3868</Stat><Stat name="Crossing Accuracy">21.55</Stat>
<Stat name="Throw Ins to Opposition Player">12</Stat>
<Stat name="Total Unsuccessful Passes ( Excl Crosses & Corners )">543</Stat>
<Stat name="Shots On Conceded Inside Box">21</Stat>
<Stat name="Throw Ins to Own Player">127</Stat>
<Stat name="Shots On Target ( inc goals )">50</Stat>
<Stat name="Clean Sheets">1</Stat>
<Player position="Defender" player_id="61021" shirtNumber="5" known_name="Leandro Castán" last_name="Castan da Silva" first_name="Leandro">
<Stat name="Time Played">90</Stat>
<Stat name="Successful Launches">1</Stat>
<Stat name="Open Play Passes">42</Stat>
<Stat name="Backward Passes">1</Stat>
</Player>
</Team>
</SeasonStatistics>
所以,我有x文件在我的目录,我需要读取所有。当我读取文件时,我想:
-美元阵列(名为teamname美元——>位置-> statval美元)
- array2美元($ playerstat——>位置——> statval美元)
我该怎么做?当第一个xml文件完成后,我如何解析下一个?
感谢大家马特奥
xml解析提示:
$content = '<xml>....</xml>';
$dom = new DOMDocument;
@$dom->loadHTML($content);