ある場合とない場合があるオプションの要素を含む XML が与えられます (..)。現在、これらのオプションの要素自体にもオプションの要素が含まれている場合があります。
<show>
...
<text>
<description> desc </description>
</text>
...
</show>
<show>
<title>I'm a show without text</title>
</show>
<show>
<text>
<subtitle>I have a text-node but no description-node in it.</subtitle>
</text>
</show>
-node の値が存在する場合は取得する必要があります。私が今やっているように、それを処理するためのより良い方法は何でしょうか:
description = show.Element("text") != null ? show.Element("text").Element("description") != null? show.Element("text").Element("description").Value : "" : ""
これは最適ではないように感じます。さらに多くのノードにクエリを実行する必要があります。