<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Search" %>
Untitled Page
File: Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.Text;
public partial class Search : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string xmlFile = Server.MapPath("Data.xml");
XmlDocument doc = new XmlDocument();
doc.Load(xmlFile);
StringBuilder str = new StringBuilder();
XmlNodeList nodes = doc.GetElementsByTagName("Title");
foreach (XmlNode node in nodes)
{
str.Append("Found: ");
string name = node.ChildNodes[0].Value;
str.Append(name);
str.Append("
");
if (name == "star 1")
{
XmlNode parent = node.ParentNode;
XmlNodeList childNodes = ((XmlElement)parent).GetElementsByTagName("Star");
foreach (XmlNode childNode in childNodes)
{
str.Append("Found Star: ");
str.Append(childNode.ChildNodes[0].Value);
str.Append("
");
}
}
}
XmlText.Text = str.ToString();
}
}
File: Data.xml
title 1
directory 2
1
star 1
star 2