日期:2014-05-20 浏览次数:20827 次
string str = @"<input cmdcode = ""0x0402"" deviceid = ""?"" userid = ""?""> <orderserial>00000000</orderserial> <ordertype>0</ordertype> <guestid>0</guestid> <tablemark/> <pce>0</pce> <dishlist number =""9""> <dish id=""010301001"" number=""100"" description="""">aaaaa</dish> <dish id=""010301002"" number=""100"" description=""bbbb""/> <dish id=""010301003"" number=""100"" description=""""/> <dish id=""010301004"" number=""100"" description=""""/> <dish id=""010301005"" number=""100"" description=""""/> <dish id=""010301006"" number=""100"" description=""""/> <dish id=""010301007"" number=""100"" description=""""/> <dish id=""010301008"" number=""100"" description=""""/> <dish id=""010301009"" number=""100"" description=""""/> </dishlist> </input>"; XmlDocument xml = new XmlDocument(); xml.LoadXml(str); XmlNode dish = xml.SelectSingleNode("//dish[@id='010301001']"); Console.WriteLine(dish.InnerText); XmlNode dish2 = xml.SelectSingleNode("//dish[@id='010301002']"); Console.WriteLine(dish2.Attributes["description"].Value);