<?xml version="1.0" encoding="utf-8" ?><xml> <exception> <modeule id="test1"> <tipMessage id="m001">連接數(shù)據(jù)庫失敗</tipMessage> <tipMessage id="m002">刪除失敗</tipMessage> </modeule> <modeule id="test2"> <tipMessage id="m001">連接數(shù)據(jù)庫失敗</tipMessage> <tipMessage id="m002">刪除失敗</tipMessage> </modeule> </exception> <message> <module id="test3"> <tipMessage id="m001">連接數(shù)據(jù)庫失敗</tipMessage> <tipMessage id="m002">刪除失敗</tipMessage> </module> </message></xml>以上為一個XML文件,我想根據(jù)我傳入的參數(shù)“test1”和“m001”讀出節(jié)點 <tipMessage id="m001">連接數(shù)據(jù)庫失敗</tipMessage>的值,高手請指點
2 回答

叮當(dāng)貓咪
TA貢獻(xiàn)1776條經(jīng)驗 獲得超12個贊
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml.Linq; namespace XmlTest { class Program { static void Main(string[] args) { var doc = XDocument.Load("data.xml"); var value = (from node in doc.Descendants("modeule") where node.Attribute("id").Value == "test1" from tip in node.Elements("tipMessage") where tip.Attribute("id").Value == "m001" select tip.Value).FirstOrDefault(); Console.WriteLine(value); Console.ReadLine(); } } }
- 2 回答
- 0 關(guān)注
- 981 瀏覽
添加回答
舉報
0/150
提交
取消