如何检查C#中是否存在xml标记? 我的Xml
<name>
<firstname>John</firstname>
<lastname>cena</lastname>
<job>Administrator</job>
<location>sunnyvale</location>
<age>19</age>
</name>
<name>
<firstname>mark</firstname>
<job>Agent</job>
<location>Bangalore</location>
<age>22</age>
</name>
lastname标签不存在,用于标记如何签入C#?
答案 0 :(得分:1)
string xml = @"
<name>
<firstname>mark</firstname>
<job>Agent</job>
<location>Bangalore</location>
<age>22</age>
</name>";
var doc = XDocument.Parse(xml);
bool isLastNameExists = doc.Descendants("name").Elements("lastname").Any();