<?xml version="1.0" ?><MotePacket><ParsedDataElement><Name>amtype</Name><ConvertedValue>11</ConvertedValue></ParsedDataElement><ParsedDataElement><Name>nodeid</Name><ConvertedValue>1</ConvertedValue></ParsedDataElement><ParsedDataElement><Name>parent</Name><ConvertedValue>0</ConvertedValue></ParsedDataElement><ParsedDataElement><Name>group</Name><ConvertedValue>125</ConvertedValue></ParsedDataElement><ParsedDataElement><Name>socketid</Name><ConvertedValue>51</ConvertedValue></ParsedDataElement><ParsedDataElement><Name>board_id</Name><ConvertedValue>132</ConvertedValue></ParsedDataElement><ParsedDataElement><Name>packet_id</Name><ConvertedValue>129</ConvertedValue></ParsedDataElement><ParsedDataElement><Name>voltage</Name><ConvertedValue>2636</ConvertedValue></ParsedDataElement><ParsedDataElement><Name>temp</Name><ConvertedValue>25.519222</ConvertedValue></ParsedDataElement><ParsedDataElement><Name>light</Name><ConvertedValue>1543</ConvertedValue></ParsedDataElement><ParsedDataElement><Name>mic</Name><ConvertedValue>313</ConvertedValue></ParsedDataElement><ParsedDataElement><Name>accel_x</Name><ConvertedValue>-1660.000000</ConvertedValue></ParsedDataElement><ParsedDataElement><Name>accel_y</Name><ConvertedValue>960.000000</ConvertedValue></ParsedDataElement><ParsedDataElement><Name>mag_x</Name><ConvertedValue>30.790493</ConvertedValue></ParsedDataElement><ParsedDataElement><Name>mag_y</Name><ConvertedValue>30.790493</ConvertedValue></ParsedDataElement></MotePacket> <?xml version="1.0" ?><MotePacket><ParsedDataElement><Name>amtype</Name><ConvertedValue>11</ConvertedValue></ParsedDataElement><ParsedDataElement><Name>nodeid</Name><ConvertedValue>1</ConvertedValue></ParsedDataElement><ParsedDataElement><Name>parent</Name><ConvertedValue>0</ConvertedValue></ParsedDataElement><ParsedDataElement><Name>group</Name><ConvertedValue>125</ConvertedValue></ParsedDataElement><ParsedDataElement><Name>socketid</Name><ConvertedValue>51</ConvertedValue></ParsedDataElement><ParsedDataElement><Name>board_id</Name><ConvertedValue>132</ConvertedValue></ParsedDataElement><ParsedDataElement><Name>packet_id</Name><ConvertedValue>129</ConvertedValue></ParsedDataElement><ParsedDataElement><Name>voltage</Name><ConvertedValue>2614</ConvertedValue></ParsedDataElement><ParsedDataElement><Name>temp</Name><ConvertedValue>22.881853</ConvertedValue></ParsedDataElement><ParsedDataElement><Name>light</Name><ConvertedValue>1983</ConvertedValue></ParsedDataElement><ParsedDataElement><Name>mic</Name><ConvertedValue>285</ConvertedValue></ParsedDataElement><ParsedDataElement><Name>accel_x</Name><ConvertedValue>-80.000000</ConvertedValue></ParsedDataElement><ParsedDataElement><Name>accel_y</Name><ConvertedValue>520.000000</ConvertedValue></ParsedDataElement><ParsedDataElement><Name>mag_x</Name><ConvertedValue>30.925539</ConvertedValue></ParsedDataElement><ParsedDataElement><Name>mag_y</Name><ConvertedValue>30.790493</ConvertedValue></ParsedDataElement></MotePacket>
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Xml; using System.Xml.XPath; namespace read_xml_elements { public partial class Form1 : Form { public Form1() { InitializeComponent(); XmlTextReader Reader = new XmlTextReader("C:\\Memsic\\cygwin\\home\\admin\\22.xml"); XmlDocument doc = new XmlDocument(); doc.Load(Reader); XPathNavigator nav = doc.CreateNavigator(); //compile xpath XPathExpression expr; expr = nav.Compile("/MotePacket/ParsedDataElement/[Name='light']"); XPathNodeIterator iterator = nav.Select(expr); //iterate node set listBox1.Items.Clear(); try { while (iterator.MoveNext()) { XPathNavigator nav2 = iterator.Current.Clone(); listBox1.Items.Add("Name: " + nav2.Value); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } } }
using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Windows.Forms; using System.Xml.Linq; ... XElement _x = XElement.Load(@"22.xml"); var lightElements = from page in _x.Elements("ParsedDataElement") where page.Element("Name").Value == "light" select page; foreach (var item in lightElements) { listBox1.Items.Add(item.Element("ConvertedValue").Value); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)