<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="XPathSearch" %>
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 XPathSearch : 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);
XmlNodeList nodes = doc.SelectNodes("/DvdList/DVD/Title[../@Category='Category 1']");
StringBuilder str = new StringBuilder();
foreach (XmlNode node in nodes)
{
str.Append("Found: ");
str.Append(node.ChildNodes[0].Value);
str.Append("
");
}
XmlText.Text = str.ToString();
}
}
File: Data.xml
title 1
directory 2
1
star 1
star 2
title 2
directory 2
2
star 3
star 4