0

時間ノードの属性値で構成されるドロップダウンがあります。親属性の値に応じてサブサブ子ノード属性を選択したい

xmlは次のとおりです

<info>
<time value="0-30">
  <id t_id="1" speaker="Rajesh "  desc="welcome" />
  <id t_id="2" speaker="Deepak "  desc="to the meeting" />
</time>
<time value="31-50">
  <id t_id="1" speaker="Vishal"  desc="welcome" />
  <id t_id="2" speaker="Vikas"  desc="to the meeting" />
</time>
</info>

ドロップダウンで 0-30 を選択すると、Rajesh と Deepak が表示される必要があります

私はlinqを使用しようとしています

私を助けてください

4

1 に答える 1

0

一致する時間要素を選択し、子孫の id 要素を平坦化します

XDocument xdoc = XDocument.Load(path_to_xml);
var speakers = xdoc.Descendants("time")
                   .Where(t => (string)t.Attribute("value") == "0-30")
                   .SelectMany(t => t.Descendants("id"))
                   .Select(id => (string)id.Attribute("speaker"));

クエリ構文

var speakers = from t in xdoc.Descendants("time")
               where (string)t.Attribute("value") == "0-30"
               from id in t.Descendants("id")
               select (string)id.Attribute("speaker");

XPath

var speakers = from id in xdoc.XPathSelectElements("//time[@value='0-30']/id")
               select (string)id.Attribute("speaker");
于 2013-06-24T10:37:23.433 に答える