迅速で汚いニュースシステムを作ろうとしています。
基本的なXMLファイルを用意します。
<?xml version="1.0" encoding="ISO-8859-1"?>
<articles>
<article id="1">
<title>Article title 001</title>
<short>Short text</short>
<long>Long text</long>
</article>
<article id="2">
<title>Article title 002</title>
<short>Short text</short>
<long>Long text</long>
</article>
</articles>
次のコードですべての記事を表示できます。
<?php
$xmldoc = new DOMDocument();
$xmldoc->load('test.xml');
$xpathvar = new Domxpath($xmldoc);
$queryResult = $xpathvar->query('//articles/article'); // works fine grabs all articles
foreach($queryResult as $result){
echo $result->textContent;
}
?>
IDに基づいて1つの記事だけを表示する方法がわかりません。
どんな助けでも素晴らしいでしょう。
ありがとうステファン