⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 search-navigator.aspx

📁 东软内部材料(四)asp等相关的教学案例 
💻 ASPX
字号:
<%@Page Language="C#" %>
<%@Import Namespace="System.Xml" %>
<%@Import Namespace="System.Xml.XPath" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head>
<title>Searching an Xml document with an XPathNavigator</title>
<!-- #include file="..\global\style.inc" -->
</head>
<body bgcolor="#ffffff">
<span class="heading">Searching an Xml document with an XPathNavigator</span><hr />
<!--------------------------------------------------------------------------->

<div id="outDocURL" runat="server"></div>
<div id="outError" runat="server">&nbsp;</div>
<div id="outResults" runat="server"></div>

<script language="C#" runat="server">

	void Page_Load(Object sender, EventArgs e)
	{
		// create physical path to booklist.xml sample file (in same folder as ASPX page)
		string strCurrentPath = Request.PhysicalPath;
		string strXmlPath = strCurrentPath.Substring(0, strCurrentPath.LastIndexOf("\\")) + "\\booklist.xml";

		// declare a variable within current scope to hold an XPathDocument
		XPathDocument objXPathDoc;

		try
		{
			// create XPathDocument object and load the Xml file
			objXPathDoc = new XPathDocument(strXmlPath);
			outDocURL.InnerHtml = "Loaded file: <b>" + strXmlPath + "</b>";
		}
		catch (Exception objError)
		{
			// display error details
			outError.InnerHtml = "<b>* Error while accessing document</b>.<br />"
						+ objError.Message + "<br />" + objError.Source;
			return; //  and stop execution
		}

		// now ready to parse the Xml document
		// it must be well-formed to have loaded without error

		// create a new XPathNavigator object using the XPathDocument object
		XPathNavigator objXPNav = objXPathDoc.CreateNavigator();

		// create a string to hold the matching values found
		string strResults = "<b>List of authors</b>:<br />";

		// select all the AuthorName nodes into an XPathNodeIterator object
		// using an XPath expression
		XPathNodeIterator objXPIter;
		objXPIter = objXPNav.Select("descendant::AuthorName");

		// iterate through the nodes. Each "node" in the XPathNodeIterator is
		// itself an XPathNavigator, so Name and Value properties are available
		while (objXPIter.MoveNext())
		{
			// get the value and add to the // results' string
			strResults += objXPIter.Current.Value + "<br />";
		}

		outResults.InnerHtml = strResults;   // display the result

	}

</script>

<!--------------------------------------------------------------------------->
<!-- #include file="..\global\foot.inc" -->
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -