You are on page 1of 4

Practical no 15

Channel.xml
<?xml version="1.0" encoding="utf-8" ?>
<CableTV>
<Channel name="POGO">
<Language>Hindi</Language>
<Categary>Cartoon</Categary>
</Channel>

<Channel name="Disney">
<Language>English</Language>
<Categary>Cartoon</Categary>
</Channel>

<Channel name="AajTak">
<Language>Hindi</Language>
<Categary>News</Categary>
</Channel>

<Channel name="History">
<Language>English</Language>
<Categary>News</Categary>
</Channel>

</CableTV>

XmlTest.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="XmlTest.aspx.cs"
Inherits="practical_15.XmlTest" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
width: 100%;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<table class="auto-style1">
<tr>
<td>
<h2>Monkey.D.Luffy</h2>
</td>
<td>&nbsp;</td>
</tr><tr>
<td>&nbsp;</td>
<td>&nbsp;</td></tr>
</table>
<table class="auto-style1">
<tr><td>
<asp:DropDownList ID="ddlChannel" runat="server" AutoPostBack="True">
<asp:ListItem>Cartoon</asp:ListItem>
<asp:ListItem>News</asp:ListItem>
</asp:DropDownList>
</td><td>
<asp:DropDownList ID="ddlLanguage" runat="server" AutoPostBack="True">
<asp:ListItem>English</asp:ListItem>
<asp:ListItem>Hindi</asp:ListItem>
</asp:DropDownList>
</td></tr><tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr><tr><td>
<asp:Button ID="btnShow" runat="server" OnClick="btnShow_Click"
Text="Show" />
</td><td>&nbsp;</td>
</tr><tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr><tr><td>
<asp:Label ID="lblResult" runat="server" Text="ore datte kaizoku ni naritain da
yo"></asp:Label>
</td>
<td>&nbsp;</td>
</tr>
</table>
</div>
</form>
</body>
</html>
XmlTest.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
namespace practical_15
{
public partial class XmlTest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void btnShow_Click(object sender, EventArgs e)


{
XmlDocument doc = new XmlDocument();
doc.Load("C:\\Users\\prath\\source\\repos\\practical 15\\practical 15\\Channels.xml");
lblResult.Text = "ore datte kaizoku ni naritain da yo";
foreach (XmlElement element in doc.DocumentElement.ChildNodes) {
String ch = element.GetAttribute("name");
if ((element.ChildNodes[1].InnerText == ddlChannel.Text) &&
(element.ChildNodes[0].InnerText == ddlLanguage.Text))
{
lblResult.Text = ch + "<br>";
}
}
}
}
}
Output:

You might also like