<?xml version="1.0" encoding="utf-8" ?>
<employees>
  <employee on="01">
    <name>Tom</name>
    <sex>男</sex>
    <birth>
      <year>1982</year>
      <month>5</month>
      <day>22</day>
    </birth>
    <sales>
      <year>2010</year>
      <month>1</month>
      <sale>320000</sale>
    </sales>
    <salary>8600</salary>
  </employee>
  
  <employee on="02">
    <name>Jack</name>
    <sex>男</sex>
    <birth>
      <year>1981</year>
      <month>7</month>
      <day>10</day>
    </birth>
    <sales>
      <year>2010</year>
      <month>1</month>
      <sale>300000</sale>
    </sales>
    <salary>6000</salary>
  </employee>
  <employee on="03">
    <name>Jennifer</name>
    <sex>女</sex>
    <birth>
      <year>1982</year>
      <month>6</month>
      <day>22</day>
    </birth>
    <sales>
      <year>2010</year>
      <month>1</month>
      <sale>500000</sale>
    </sales>
    <salary>7000</salary>
  </employee>
  
</employees>
=============================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.XPath;
namespace WebApplication
{
    public partial class XPathNav : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
        protected void btnNav_Click(object sender, EventArgs e)
        {
            //创建XPathDocument对象
            XPathDocument xdoc = new XPathDocument(Server.MapPath("~/employees.xml")); 
            //创建Xpath导航
            XPathNavigator xnav = xdoc.CreateNavigator();
            //装入迭代器(结果)
            XPathNodeIterator iterator = xnav.Select("descendant::employee");  
            string outPut = "";
            while(iterator.MoveNext()){
                outPut += "员工:" + iterator.Current.SelectSingleNode("name").Value+"<br/>"; //在当前节点下查找单一的节点name的值
                outPut += " " + "工资:" + iterator.Current.SelectSingleNode("salary").Value + "<br/>"; // 在当前节点下查找单一的节点salary的值
                outPut += "<hr>";
            }
            outPut += "<hr>";
            Int32 avgSal = (Int32)(Double)xnav.Evaluate("sum(//employee/salary) div count(//employee)");
            outPut += "平均工资:¥"+avgSal.ToString();
            this.divOut.InnerHtml = outPut;
        }
    }
}
===================================================================
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="XPathNav.aspx.cs" Inherits="WebApplication.XPathNav" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
         <asp:Button runat="server" ID="btnNav" Text="Navigate" OnClick="btnNav_Click"  />
         <div runat="server" id="divOut">
         </div>
    </div>
    </form>
</body>
</html>
=================================================================

XPath相关笔记的更多相关文章

  1. HTTPS证书申请相关笔记

    申请免费的HTTPS证书相关资料 参考资料: HTTPS 检测 苹果ATS检测 什么是ECC证书? 渠道2: Let's Encrypt 优点 缺点 Let's Encrypt 的是否支持非80,44 ...

  2. JNI相关笔记 [TOC]

    JNI相关笔记 目录 JNI相关笔记 1 生成native code所需要的头文件 2 JNI提供的一些函数和方法 3 局部引用,全局引用,全局弱引用. 4 异常 1 生成native code所需要 ...

  3. Xpath学习笔记

    最近复习自己上一年的课本,想起来刚学那个时候想做一个写日记的软件. 想不如做,用控制台瞎写了一个,一做就成了,没什么bug,期间使用Xpath来读数据,所以就稍微学了一下. 学习过程就这样做一点笔记, ...

  4. Hadoop相关笔记

    一.            Zookeeper( 分布式协调服务框架 ) 1.    Zookeeper概述和集群搭建: (1)       Zookeeper概述: Zookeeper 是一个分布式 ...

  5. XPath路径表达式笔记(转载)

    简单说,xpath就是选择XML文件中节点的方法. 所谓节点(node),就是XML文件的最小构成单位,一共分成7种. - element(元素节点)- attribute(属性节点)- text ( ...

  6. redis相关笔记(二.集群配置及使用)

    redis笔记一 redis笔记二 redis笔记三 1.配置:在原redis-sentinel文件夹中添加{8337,8338,8339,8340}文件夹,且复制原8333中的配置 在上述8333配 ...

  7. redis相关笔记(三.redis设计与实现(笔记))

    redis笔记一 redis笔记二 redis笔记三 1.数据结构 1.1.简单动态字符串: 其属性有int len:长度,int free:空闲长度,char[] bur:字符数组(内容) 获取字符 ...

  8. Windows API 进程相关笔记

    0. 前言 最近做了一个进程信息相关的项目,整理了一下自己做项目时的笔记,分享给大家 1. 相关概念 1.1 HANDLE 概念 HANDLE(句柄)是Windows操作系统中的一个概念. 在Wind ...

  9. PHP相关笔记

    扩展包(相关链接):https://packagist.org/: 插件postman主要应用于web开发时get.post请求时查看其响应:

随机推荐

  1. Python爬虫学习——使用Cookie登录新浪微博

    1.首先在浏览器中进入WAP版微博的网址,因为手机版微博的内容较为简洁,方便后续使用正则表达式或者beautifulSoup等工具对所需要内容进行过滤 https://login.weibo.cn/l ...

  2. js 数组常用的操作函数整理

    平时多做企业应用开发,抱着实用为主,对前端技术理解得比较肤浅,下面就是肤浅地对 js 数组的属性和方法及对它操作的 jquery 方法做些记录: js 数组是 js 内建的一个非常强大数据类型,由于 ...

  3. .NET并行与多线程学习系列一

    并行与多线程学习系列一 一.并行初试: public static void test() { ; i < ; i++) { Console.WriteLine(i); } } public s ...

  4. python3.4 data type

    #coding=utf-8 #Python 3.4 https://docs.python.org/3.4/library/ #IDE:Eclipse +PyDev Window10 import a ...

  5. 标签<a>的注意事项1

    使用a标签时,其子元素可以为其他元素,但是不能包含<a>标签,否则会造成布局改变! 因此请尽量不要在a标签里放太多子元素,可以在外层套一个div,其他子元素放在a标签同级下. 正确布局: ...

  6. CodeForces 645A Amity Assessment

    简单模拟. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #incl ...

  7. 黄聪:VPS服务器好备份工具配置

  8. Writing clean code is what you must do in order to call yourself a professional.

    Clean Code  A Handbook of Agile Software Craftsmanship

  9. Java学习笔记-Json

    //先导入gson到lib,add build path //2015年5月5日22:02:37 package com.alfredsun.thread; import com.google.gso ...

  10. spring boot maven 插件

    spirng boot 需要使用专用maven插件打包,才能打包.引入如下. <build>        <plugins>            <plugin> ...