Potrzebuję przeczytać wszystkie Child Nodes
z mojego tagu <Imovel>
, problem polega na tym, że mam więcej niż 1 (jeden) znacznik <Imovel>
w moim pliku XML i różnicę między każdą etykietą <Imovel>
jest atrybutem o nazwie ID.Przeczytaj wszystkie węzły potomne XML każdego konkretnego węzła.
To jest przykład
<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>
muszę przeczytać wszystkie znaczniki każdego tagu <Imovel>
, aw końcu każdego walidacji, które robię w moim <Imovel>
tagu muszę zrobić kolejny walidacji.
Tak, myślę, że trzeba zrobić 2 (dwóch) foreach
lub for
i foreach
, nie rozumiem bardzo dobrze o LINQ
ale podążać moja próbka
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;
}
}
Ale nie działa bardzo Cóż, w moim oświadczeniu foreach
ponieważ mój tag <Picture>
, jej tag macierzysty nie ma atrybutu ID.
Ktoś może mi pomóc w tej metodzie?
'ale nie działa bardzo dobrze, moim foreach statement.' można wyjaśnić, co rozumiemy przez to? –
Tak, to znaczy, że rodzic mojego tagu "