zoukankan      html  css  js  c++  java
  • XPath相关笔记

    <?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>
    =================================================================
  • 相关阅读:
    SharePoint 2013 商务智能报表发布
    sharepoint designer web 服务器似乎没有安装microsoft sharepoint foundation
    SharePoint 2013 Designer系列之数据视图
    SharePoint 2013 Designer系列之数据视图筛选
    SharePoint 2013 Designer系列之自定义列表表单
    SharePoint 2013 入门教程之创建及修改母版页
    SharePoint 2013 入门教程之创建页面布局及页面
    SharePoint 2010 级联下拉列表 (Cascading DropDownList)
    使用SharePoint Designer定制开发专家库系统实例!
    PL/SQL Developer 建立远程连接数据库的配置 和安装包+汉化包+注册机
  • 原文地址:https://www.cnblogs.com/blogLYF/p/5653954.html
Copyright © 2011-2022 走看看