Write a script to create “cricket.xml” file with multiple elements as
given below
<Cricket team>
<Country = India>
<Player Name >-------- <Player Name >
<Wickets>--------- </Wickets>
<Runs>--------</Runs>
</Country>
</Cricket team>
Also add country = “England” and its elements
cricket.php
<?php
$doc=new DOMDocument("1.0","UTF-8");
$xmlfile="cricket.xml";
$root=$doc->createElement("Cricket_team");
$country=$doc->createElement("Country");
$country->setAttributeNode(new DOMAttr('Id','India'));
$pn=$doc->createElement("Player_Name","Sachin");
$country->appendChild($pn);
$w=$doc->createElement("Wicket",2);
$country->appendChild($w);
$r=$doc->createElement("Runs",150);
$country->appendChild($r);
$c=$doc->createElement("Country");
$c->setAttributeNode(new DOMAttr('Id','England'));
$pn=$doc->createElement("Player_Name","Dhoni");
$c->appendChild($pn);
$w=$doc->createElement("Wicket",4);
$c->appendChild($w);
$r=$doc->createElement("Runs",140);
$c->appendChild($r);
$root->appendChild($country);
$root->appendChild($c);
$doc->appendChild($root);
$doc->save("cricket.xml");
echo '<a href="cricket.xml">Click Here </a>';
?>

0 Comments
If anyone has Doubts or suggestions please let me know