Good morning people,
I am still learning how to use LINQ and now im struggle with this situation.
I have this Xml file (example)
<Results> <PrxComissao> <Id>0</Id> <NumErro>0</NumErro> <RetCode>0</RetCode> <IdEvento>0</IdEvento> <ExecutionTimeMilliseconds>63596143450994.227</ExecutionTimeMilliseconds> <ExecutionTimeSeconds>63596143450.994225</ExecutionTimeSeconds> <CodComissao>CFE</CodComissao> <Montante>20.00</Montante> <Percentagem>0.0000</Percentagem> <MntMin>0.00</MntMin> <MntMax>0.00</MntMax> <Nome>CFE</Nome> <Descricao>Custo Factura Estrangeiro</Descricao> </PrxComissao> <PrxComissao> <Id>0</Id> <NumErro>0</NumErro> <RetCode>0</RetCode> <IdEvento>0</IdEvento> <ExecutionTimeMilliseconds>63596143450994.227</ExecutionTimeMilliseconds> <ExecutionTimeSeconds>63596143450.994225</ExecutionTimeSeconds> <CodComissao>CFE</CodComissao> <Montante>20.00</Montante> <Percentagem>0.0000</Percentagem> <MntMin>13.00</MntMin> <MntMax>123.00</MntMax> <Nome>CFE</Nome> <Descricao>www</Descricao> </PrxComissao> </Results> And now what I want to do is get all the xml elements inside the "PrxComissao", and then assign them to my class. This is the code I was trying
XDocument xDoc = XDocument.Parse(resultado); List<PrxComissao> lstPrxComissao = xDoc.Elements("Results") .Elements("PrxComissao") .Elements() .Select(BL_CartaoCredito.Utils.Data.Converter.FromXElement<PrxComissao>) .ToList(); ObjAuxResult = lstPrxComissao; What I am trying to do with this Converter.FromXElement<PrxComissao> is get all that elements and assign them.
Here is my class
public class PrxComissao { public string CodComissao { get; set; } public string Montante { get; set; } public string Percentagem { get; set; } public string MntMin { get; set; } public string MntMax { get; set; } public string Nome { get; set; } public string Descricao { get; set; } public string TipoImposto { get; set; } public string ComFinanciamento { get; set; } public string iActivo { get; set; } public string UtlModificacao { get; set; } public string DtModificacao { get; set; } public string UtlCriacao { get; set; } public string DtCriacao { get; set; } } So now I have two problems. 1st I can't get to the elements inside PrxComissao always returns me nothing and them is my Linq Select correct ? Or is there a better way ?
Thank you for your time
No comments:
Post a Comment