0

我正在开发一个应用程序,其中我使用两个看起来像这样的 XML 文档:

第一:

<?xml version='1.0' encoding='ISO-8859-1'?>
<!DOCTYPE markables SYSTEM "markables.dtd">
<markables xmlns="www.eml.org/NameSpaces/coref">
<markable id="markable_1" mmax_level="coref" span="word_1..word_4"> </markable>
<markable id="markable_2" mmax_level="coref" span="word_6..word_7"> </markable>
<markable id="markable_3" mmax_level="coref" span="word_10..word_24"> </markable>
</markables>

第二个:

<?xml version='1.0' encoding='ISO-8859-1'?>
<!DOCTYPE words SYSTEM "words.dtd">
<words>
<word id="word_1">Alfa</word>
<word id="word_2">Beta</word>
<word id="word_3">Gamma</word>
<word id="word_4">Delta</word>
<word id="word_5">Zeta</word>
</words>

然后我想使用 PHP5 和 DOM 对它们进行一些操作。这是PHP代码:

<?php

$xmlHitzakDok = new DOMDocument();
$xmlMarkDok = new DOMDocument();
if($xmlHitzakDok->load("words.xml") === FALSE){die('Errorea hitzen xml-a kargatzean');}
if($xmlMarkDok->load("coref.xml") === FALSE){die('Errorea markagarrien xml-a kargatzean');}
$xPath_Hitzak = new DOMXPath($xmlHitzakDok);
$xPath_Mark = new DOMXPath($xmlMarkDok);

$Hurrengo_HitzaID = "word_5";
$kont = 0;

foreach ($xPath_Hitzak->query('//words/word') AS $Hitza)
{
  $HitzaID = $Hitza->getAttribute('id');
    if ($HitzaID == $Hurrengo_HitzaID)
    {//GETS INTO HERE
           foreach ($xPath_Mark->query('//markables/markable') AS $Markagarria)
               {//DOESNT GET INTO HERE
          echo $HitzaID;
           }
        }
}

我遇到的问题是我不知道为什么在运行代码时它没有进入嵌套的 foreach。有什么解决办法吗?

4

0 回答 0