How can I read the tag using linq2xml?
var q = (from c in xDocument.Descendants("colecciones").Descendants("BoTblPacientes")
select c).ToList();
but dont work.
<?xml version="1.0" ?>
<DalClassObject xmlns="http://www.asd.com">
<objeto class="BoTblPacientes"></objeto>
<validador>true</validador>
<mensaje>El paciente existe en el sistema .</mensaje>
<colecciones>
<BoTblPacientes>
<tblpacientesmotivoconsulta>5</tblpacientesmotivoconsulta>
<tblpacientestlfcasa>5</tblpacientestlfcasa>
<tblpacientescelular>5</tblpacientescelular>
<tblpacientesoficina>5</tblpacientesoficina>
<tblpacientescorreo>5</tblpacientescorreo>
<tblpacientesdireccion>5</tblpacientesdireccion>
<tblpacientesapellidos>5</tblpacientesapellidos>
<tblpacientesdocumento>5</tblpacientesdocumento>
<tblpacientessexoid>0</tblpacientessexoid>
<tblpacientesfechanacimiento class="sql-date">2012-05-13</tblpacientesfechanacimiento>
<tblpacientesnombres>5</tblpacientesnombres>
<tblpacientesid>2</tblpacientesid>
<tblpacientesestadocivil>0</tblpacientesestadocivil>
<tblpacientesfecharegistro class="sql-date">2012-05-13</tblpacientesfecharegistro>
<tblpacienteidmaster>0</tblpacienteidmaster>
</BoTblPacientes>
<BoTblPacientes>
<tblpacientesmotivoconsulta>23232</tblpacientesmotivoconsulta>
<tblpacientestlfcasa>2332</tblpacientestlfcasa>
<tblpacientescelular>23</tblpacientescelular>
<tblpacientesoficina>23</tblpacientesoficina>
<tblpacientescorreo>23</tblpacientescorreo>
<tblpacientesdireccion>2323</tblpacientesdireccion>
<tblpacientesapellidos>ewr</tblpacientesapellidos>
<tblpacientesdocumento>5</tblpacientesdocumento>
<tblpacientessexoid>0</tblpacientessexoid>
<tblpacientesfechanacimiento class="sql-date">2012-03-29</tblpacientesfechanacimiento>
<tblpacientesnombres>wer</tblpacientesnombres>
<tblpacientesid>3</tblpacientesid>
<tblpacientesestadocivil>0</tblpacientesestadocivil>
<tblpacientesfecharegistro class="sql-date">2012-05-13</tblpacientesfecharegistro>
<tblpacienteidmaster>0</tblpacienteidmaster>
</BoTblPacientes>
</colecciones>
</DalClassObject>
Your initial “but doesn’t work” statement isn’t very helpful as you are not really clarifying what isn’t working, but from the error i see, I am going to guess that your query isn’t selecting anything.
Your xml root element declares a namespace but you are not specifying that namespace in the query, as a result nothing matches the string you are providing in the
Descendants()method.You need to look up by the local name instead
Just for completeness sake, as mentioned by OP in the comments, another option is to add the namespace to the query instead: