XmlAttributeReading.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>xml attribute reading example in php</title>
</head>
<body>
<h3>xml attribute reading example in php</h3>
<?php
$xml = simplexml_load_file("patients3.xml");
foreach($xml->children() as $patients)
{
foreach($patients->children() as $patient => $thisPatient)
{
echo $thisPatient->name;
echo " ";
echo $thisPatient->name['lastname'];
/*
|-------------------------------------------------
| lastname is the attribute of name
|-------------------------------------------------
*/
echo " ";
echo $thisPatient->address;
echo "<br />";
}
}
?>
</body>
</html>
patients3.xml
<?xml version="1.0"?>
<documents>
<patients>
<patient>
<name lastname="hosan">iqbal</name>
<address>uttara</address>
</patient>
<patient>
<name lastname="saiful">suman</name>
<address>mohakhali</address>
</patient>
</patients>
</documents>
No comments:
Post a Comment
leave your comments here..