如何解析多个xml文件

时间:2015-10-15 15:15:40

标签: php xml xml-parsing simplexml php-parser

我需要实现一个PHP文件来从目录中读取x文件,并且每次更新数据库中的表。随着更新没有问题但是,我在php中的xml并不是最好的。所以,这是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个文件,我需要阅读所有文件。当我正在阅读我想要的文件时:

  

- $ array($ teamname -----&gt; $ position - &gt; $ statval)
   - $ array2($ playerstat ----&gt; $ position -----&gt; $ statval)

我该怎么做?当第一个xml的文件将完成我如何解析下一个?

对所有人来说 利玛

1 个答案:

答案 0 :(得分:0)

提示解析xml:

$content = '<xml>....</xml>';
$dom = new DOMDocument;
@$dom->loadHTML($content);