2

次のような XML ファイルがあります。

<subject KL="1">
    <subjectName>If-Else</subjectName>
    <theory>
       <tutorial>...</tutorial>
       <full>...</full>
    </theory>
</subject>

そして、次のPHPコードでそれを抽出しようとします:

$subjects = $doc->getElementsByTagName( "subject" );
foreach( $subjects as $subject ) {
      $knowledgeLevel = $subject->getAttribute( "KL" );
      $names = $subject->getElementsByTagName( "subjectName" );
      $name = $names->item(0)->nodeValue;

      $theory = $subject->getElementsByTagName( "theory" );
      $shorts = $theory->getElementsByTagName( "tutorial" );
      $short = $shorts->item(0)->nodeValue;
      $longs = $theory->getElementsByTagName( "full" );
      $long = $longs->item(0)->nodeValue;

      $subs [] = array (
            'knowledgeLevel' => $knowledgeLevel,
            'name' => $name,
            'shortTheory' => $short,
            'longTheory' => $long
      );
}

しかし、私のブラウザはエラーを出します

Call to undefined method DOMNodeList::getElementsByTagName()

コード スニペットの 8 行目。なぜそれがうまくいかないのか分かりません。何か助けはありますか?

4

2 に答える 2