TY_BCA_AWT_SLIP 28_2


28. Write a PHP script to accept an .XML file which should comprise the following:
<cricket>
<player>abc</player>
<runs>1000</runs>
<wickets>50</wickets>
<noofnotout>10</noofnotout>
</cricket>
For at least 5 players.
Display the details of players who have scored more than 1000 runs and at least 50 wickets.


XML file :

<?xml version='1.0' encoding='UTF-8'?>
<cricketinfo>
            <cricket>
                        <player>abc</player>
                        <runs>1000</runs>
                        <wickets>50</wickets>
                        <noofnotout>10</noofnotout>
            </cricket>

            <cricket>
                        <player>def</player>
                        <runs>100</runs>
                        <wickets>40</wickets>
                        <noofnotout>10</noofnotout>
            </cricket>

            <cricket>
                        <player>pqr</player>
                        <runs>1020</runs>
                        <wickets>60</wickets>
                        <noofnotout>10</noofnotout>
            </cricket>

            <cricket>
                        <player>xyz</player>
                        <runs>9000</runs>
                        <wickets>90</wickets>
                        <noofnotout>40</noofnotout>
            </cricket>

            <cricket>
                        <player>lmn</player>
                        <runs>170</runs>
                        <wickets>80</wickets>
                        <noofnotout>8</noofnotout>
            </cricket>
</cricketinfo>

Php file :

<?php
$d=new DOMDocument();
$d->load("slip_29.xml");

$run=$d->getElementsByTagName('runs');
$wic=$d->getElementsByTagName('wickets');
$name=$d->getElementsByTagName('player');

foreach($name as $n)
{
            if($run=='1000' && $wic>='50')
            echo "<br>".$n->textContent;
            else "not";        
}
?>

No comments:

Post a Comment

Note: only a member of this blog may post a comment.