zoukankan      html  css  js  c++  java
  • C# 对XML操作-实例

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Xml;          // 添加
    using System.Xml.Linq;   // 添加

    namespace test
    {
        public partial class frm_TestMain : Form
        {
            private XDocument xdocCFG= new XDocument();//建立一个document文件
            string str=null;

            public frm_TestMain()
            {
                InitializeComponent();
                xdocCFG = XDocument.Load("testCFG.xml");//加载配置文件XML
                var result= from c in xdocCFG.Descendants("Jife") select c;//选中以Jife为父节点的子节点
                foreach(var item in result)
                {
                    string strValue = item.Element("age").Value;  //选取age标志下的在数据
                    str += strValue+"#";    //消息累加,便于显示。
                }

            }

            private void Form1_Load(object sender, EventArgs e)
            {

            }

            private void btn_show_Click(object sender, EventArgs e)
            {
                MessageBox.Show(str); //弹出
            }
        }
    }

    产生效果如图:

    脚本文件,dat

  • 相关阅读:
    Broadcom BCM94352z/DW1560驱动新姿势
    amd显卡更新最新驱动鼠标顿卡的解决方法
    设置 P2415Q & P2715Q 显示器使其支持 HDMI 2.0 启用 4k@60hz
    Web基础之Redis
    前端基础之AJAX
    Java基础之枚举
    解决Tomcat在idea控制台乱码问题
    JQuery基础
    JavaScript基础笔记
    前端基础之Html、CSS
  • 原文地址:https://www.cnblogs.com/jife/p/3320525.html
Copyright © 2011-2022 走看看