0
我有一个XML文件中设置像这样PHP DOMXpath未定义的变量错误
<feeds><feed id="">
<headline></headline>
<author></author>
<datetime></datetime>
<link></link>
<description></description>
</feed></feeds>
我试图XPath来从一个元素中提取属性,使用元素“ID”,但我得到一个未定义的变量每个属性的错误。这是我正在尝试使用的当前脚本。
function extractText($tag) {
foreach ($tag as $item) {
$value = $item->nodeValue;
}
return $value;
}
$doc = new DOMDocument('1.0');
$doc->load("newsfeed/newsfeed.xml");
$id = $_POST['id'];
$domx = new DOMXPath($doc);
$feed = $domx->query("feeds/feed[@id='$id']");
foreach ($feed as $theid) {
$h_array = $theid->getAttribute('headline');
$headline = extractText($h_array);
$a_array = $theid->getAttribute('author');
$author = extractText($a_array);
$l_array = $theid->getAttribute("link");
$link = extractText($l_array);
$i_array = $theid->getAttribute("image");
$image = extractText($i_array);
$d_array = $theid->getAttribute("description");
$description = extractText($d_array);
$da_array = $theid->getAttribute("datetime");
$datetime = extractText($da_array);
如果任何人都可以帮助我,或者至少让我指向正确的方向,我会非常感激。