Ho bisogno di leggere tutto il Child Nodes
del mio tag <Imovel>
, il problema è che ho più di 1 (uno) tag <Imovel>
nel mio file XML e la differenza tra ogni tag <Imovel>
è un attributo chiamato ID.Leggere tutti i nodi figlio XML di ciascun nodo specifico
Questo è un esempio
<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>
ho bisogno di leggere tutte le etichette di ogni <Imovel>
tag, e alla fine di ogni convalida che faccio nel mio tag <Imovel>
Ho bisogno di fare un altro convalida.
Quindi, penso che ho bisogno di fare 2 (due) o un foreach
for
e foreach
, non capisco molto bene di LINQ
ma seguo il mio campione
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;
}
}
ma non funziona molto beh, nella mia istruzione foreach
perché il mio tag <Picture>
, il suo tag padre non ha un attributo ID.
Qualcuno può aiutarmi a fare questo metodo?
'ma non funziona molto bene, a mio foreach statement.' si può spiegare cosa si intende con questo? –
Sì, questo è perché il padre del mio tag '