Consider the following code :
$dom = new DOMDocument();
$dom->loadXML($file);
$xmlPath = new DOMXPath($dom);
$arrNodes = $xmlPath->query('*/item');
foreach($arrNodes as $item){
//missing code
}
The $file is an xml and each item has a title and a description.
How can I display them (title and description)?
$file = "<item>
<title>test_title</title>
<desc>test</desc>
</item>";
If your item looks like this:
You could use
getElementsByTagName()andnodeValue:Are
titleanddescriptionattributes? E. g. does an item look like this:If so, you could just use
getAttribute():