c#读取xml中特定节点的值(实例)

(转载请注明出处:http://blog.csdn.net/buptgshengod


将要读取的是smoke下floortype中的value值,xml如下
   
- 
- 
- 
   
   
  
  
- 
- 
   
   
  
  
  

c#代码
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;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            
            string str = "";
            XmlDocument doc = new XmlDocument();
            doc.Load(@"e:\test.xml");//读入xml,注意@
            XmlNode node = doc.SelectSingleNode("//PropDataBucket/PropDataRow[@name='smoke']//property[@name='floortype']");//设置节点位置
            if (node != null)
            {
             
                str = node.Attributes["value"].Value;//节点下多个数值名称的选择
            }
          
            textBox1.Text = str;
          
        }
    }
}

效果如图
c#读取xml中特定节点的值(实例)_第1张图片

你可能感兴趣的:(c#)