<?xml version="1.0" encoding="utf-8"?>
<mainXML>
<items>
<item category="Dekorationer" name="Flot væg" description="Meget flot væg. Passer alle stuer." price="149" />
<item category="Fritid" name="Fodbold" description="Meget rund bold. Rørt af messi." price="600" />
</items>
</mainXML>
How can i read this?
So i can make like a php loop that outputs the category, name and description for example?
I tried and started out with this:
$doc = new DOMDocument();
$doc->load( 'ex.xml' );
$items = $doc->getElementsByTagName( "item" );
foreach( $items as $item )
{
$categorys = $item->getElementsByTagName( "category" );
$category = $categorys->item(0)->nodeValue;
echo $category . " -- ";
}
categoryis an attribute (not a tag). See XML. To obtain it via theDOMElement, usegetAttribute().