c#读取xml中特定节点的值(实例)
生活随笔
收集整理的這篇文章主要介紹了
c#读取xml中特定节点的值(实例)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
(轉載請注明出處: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;}} }
效果如圖
總結
以上是生活随笔為你收集整理的c#读取xml中特定节点的值(实例)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【android-tips】adb 常用
- 下一篇: byte数组转字符串_VS2012 C#