I have a simple XML file:
<?xml version="1.0" encoding="utf-8"?>
<ConvenioValidacao>
<convenio ven_codigo="1" tipoValidacao="CPF"></convenio>
<convenio ven_codigo="1" tipoValidacao="MATRICULA"></convenio>
<convenio ven_codigo="3" tipoValidacao="CPF"></convenio>
<convenio ven_codigo="4" tipoValidacao="CPF"></convenio>
</ConvenioValidacao>
I'm trying to do a simple query against this xml file using Linq to XML, here is what i'm doing:
var myXmlDoc = XElement.Load(filePath);
var result = from convenio in myXmlDoc.Element("ConvenioValidacao").Elements("convenio")
where (string)convenio.Attribute("ven_codigo") == "1" &&
(string)convenio.Attribute("tipoValidacao") == "CPF"
select convenio;
It is not working, I'm getting null reference exception.
What I'm doing wrong?