異なる変数のxmlファイルのさまざまな条件を使用して、異なるノードの値を取得したいとします。以下はC#でファイルから異なるノード値を簡単に取得するには?
XDocument doc = XDocument.Load(@"D:\MyFiles\test.xml", LoadOptions.PreserveWhitespace);
var a = (from x in doc.Descendants("title")
select x).First().Value;
var b = (from y in doc.Descendants("label")
where y.Ancestors("sec").Any()
select y).First().Value;
var c = (from z in doc.Descendants("sec").Attributes("id")
select z).First().Value;
が、私は1行のコードでまたは多分より少ない冗長な方法でこれを行うことができます例ですか?
をこのように:[クエリLINQのXMLへのXPathを使用](https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/linq/how-to-query-linq-to-xml-using-xpath)? – Fildor
も参照してください。https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/linq/linq-to-xml-for-xpath-users – Fildor