C#读取XML文件的问题。

2024-11-25 19:30:21
推荐回答(1个)
回答1:

是不是找到节点?还是找值?
public static string GetNodeValue(string xml,string value)
{
string val = string.Empty;
StringReader strreder = new StringReader(xml);
XmlTextReader txt = new XmlTextReader(strreder);
XDocument xdoc = XDocument.Load(txt);
var query = from q in xdoc.Descendants("Account1")
where q.Value == value
select new
{
Value = q.Value
};
foreach (var q in query)
{
val = q.Value;
break;
}
strreder.Close();
txt.Close();
return val;
}