PHP5和DOM用两个XML文档操作

时间:2012-04-23 10:48:34

标签: php xml dom

我正在开发一个应用程序,我使用两个看起来像这样的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。任何解决方案?

0 个答案:

没有答案