私の<Imovel>
タグを読む必要があります。問題は私のXMLファイルに1つ以上(1つ)<Imovel>
というタグがあり、各<Imovel>
タグの違いIDと呼ばれる属性です。各特定のノードのすべてのXML子ノードを読む
これは、例えば
<Imoveis>
<Imovel id="555">
<DateImovel>2012-01-01 00:00:00.000</DateImovel>
<Pictures>
<Picture>
<Path>hhhhh</Path>
</Picture>
</Pictures>
// Here comes a lot of another tags
</Imovel>
<Imovel id="777">
<DateImovel>2012-01-01 00:00:00.000</DateImovel>
<Pictures>
<Picture>
<Path>tttt</Path>
</Picture>
</Pictures>
// Here comes a lot of another tags
</Imovel>
</Imoveis>
である私は、各<Imovel>
タグのすべてのタグを読み取る必要がある、と私は私の<Imovel>
タグで行う各検証の終わりに私は別の検証を行う必要があります。
だから、私は、私は私のサンプル非常によくLINQ
についての理解が、従わない2(2)foreach
またはfor
とforeach
を行う必要があると思います
XmlReader rdr = XmlReader.Create(file);
XDocument doc2 = XDocument.Load(rdr);
ValidaCampos valida = new ValidaCampos();
//// Here I Count the number of `<Imovel>` tags exist in my XML File
for (int i = 1; i <= doc2.Root.Descendants().Where(x => x.Name == "Imovel").Count(); i++)
{
//// Get the ID attribute that exist in my `<Imovel>` tag
id = doc2.Root.Descendants().ElementAt(0).Attribute("id").Value;
foreach (var element in doc2.Root.Descendants().Where(x => x.Parent.Attribute("id").Value == id))
{
String name = element.Name.LocalName;
String value = element.Value;
}
}
しかし、非常に動作しません。私の<Picture>
タグのため、私のforeach
ステートメントでは、親タグにID属性がありません。
誰かがこの方法をお手伝いできますか?
を含めてください 'しかし、私のforeach statement.'にあなたはこれで何を意味するかを説明することができ、非常にうまく動作しないのですか? –
はい、私の ''タグの親にはID属性がありません –