首页 > 其他 > 详细

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

时间:2014-02-18 08:59:06      阅读:491      评论:0      收藏:0      [点我收藏+]

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


将要读取的是smoke下floortype中的value值,xml如下
  <?xml version="1.0" encoding="UTF-8" ?> 
- <PropDataBucket name="navisworks_df_floor_cicle" version="1.0">
- <PropDataRow name="smoke" index="0" type="custom">
- <target name="properties">
  <property name="floortype" value="circular" /> 
  <property name="length" value="" /> 
  </target>
  </PropDataRow>
- <PropDataRow name="navisworks_df_floor_rectangular_01" index="1" type="">
- <target name="properties">
  <property name="floortype" value="rectangular" /> 
  <property name="length" value="1000.00" /> 
  </target>
  </PropDataRow>
  </PropDataBucket>

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;
          
        }
    }
}

效果如图
bubuko.com,布布扣

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

原文:http://blog.csdn.net/buptgshengod/article/details/19342173

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!