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>
    =================================================================
  • 相关阅读:
    idea存在包但是运行项目一直报java.lang.NoClassDefFoundError的问题
    记录一次服务器大中间表优化的问题(数据倾斜的解决)
    CDH spark2切换成anaconda3的问题
    关于(我们流量表优化),分区表数据块过多,聚合又导致数据倾斜问题
    大数据(流量表)任务问题清洗生成新分区表过程
    spark2.0在IDE运行的问题
    位运算应用
    SPSS数据的图表
    SPSS数据输入
    箭头函数中的this
  • 原文地址:https://www.cnblogs.com/blogLYF/p/5653954.html
Copyright © 2011-2022 走看看