0
特定の要素がすべて存在するかどうかを確認する方法を知りたいと思います。
私は以下のコードを書いたが、私はそれが賢明だとは思わない。特定の要素がすべて存在するかどうかを確認する方法
if(xmlDoc.Descendants("ElementA").Any() && xmlDoc.Descendants("ElementB").Any() && ....
特定の要素がすべて存在するかどうかを確認する方法を知りたいと思います。
私は以下のコードを書いたが、私はそれが賢明だとは思わない。特定の要素がすべて存在するかどうかを確認する方法
if(xmlDoc.Descendants("ElementA").Any() && xmlDoc.Descendants("ElementB").Any() && ....
あなたがこれを行うことができます:あなたができる場合
if (new[] {"ElementA", "ElementB", "ElementC"}
.All(element => xmlDoc.Descendants(element).Any()))
{
}
を、私はメンバーを保存することをお勧め:
private static readonly string[] ELEMENTS = new string[]
{
"ElementA",
"ElementB",
"ElementC"
};
を代わりに毎回それを再作成するの。
if (ELEMENTS.All(element => xmlDoc.Descendants(element).Any()))
{
}
こんにちは!ありがとうございました!! – Nigiri
3つ以上の要素を検証する必要がある場合は、Xsdスキーマに従って検証することをお勧めします。 – Filburt