Please check this bellow program.
::Program::
<?php
$xml='
<books>
<book>
<name>Java complete reference</name>
<cost>256</cost>
</book>
<book>
<name>Head First PHP and Mysql</name>
<cost>389</cost>
</book>
</books>';
$dom=new DOMDocument();
$dom->loadXML($xml);
foreach ($dom->getElementsByTagName('book') as $book)
{
foreach($book->getElementsByTagName('name') as $name)
{
$names[]=$name->nodeValue;
}
foreach($book->getElementsByTagName('cost') as $cost)
{
$costs[]=$cost->nodeValue;
}
}
print_r($names);
?>
It is shows error:
DOMDocument::loadXML() [domdocument.loadxml]: Start tag expected, '<' not found in Entity
Is this correct way to do this?
If it is correct, Is there any way to get the proper result without changing this < to < and > to >?
<books>instead of<books>in the first place?