I would like to extract both attributes BODY and TYPE from the following xml and output the TYPE as div class and body as text.
For example:
foreach (...) {
echo "<div class='$type_value'>$body_value</div>"
}
My XML:
<smses>
<sms body='something' type='1' address='1234'>
<sms body='something' type='2' address='12345'>
<sms body='something' type='2' address='1234'>
</smses>
My code (so far extracting only one attribute - body):
$doc = new DOMDocument();
$doc->load('xml/sms.xml');
$path = new Domxpath($doc);
$num = $_POST["sel"];
$result = $path->query("//smses/sms[@address='$num']/@body");
foreach($result as $res)
{
echo "<div id='sms'>".$res->textContent.'</div><br/><br/>';
}
smselements (rather than theirbodyattribute), and usegetAttribute()within the loop.