Getting an XML node using LINQ
Posted
by MarceloRamires
on Stack Overflow
See other posts from Stack Overflow
or by MarceloRamires
Published on 2010-03-25T12:30:17Z
Indexed on
2010/03/25
12:43 UTC
Read the original article
Hit count: 499
Somehow, using linq I can't test it with this CUF field in the beginning:
<NFe>
<infNFe versao="1.0" Id="NFe0000000000">
<ide>
<cUF>35</cUF>
<!--...-->
</ide>
</NFe>
With the following code:
XDocument document = XDocument.Load(@"c:\nota.xml");
var query = from NFe in document.Descendants("NFe")
select new
{
cuf = NFe.Element("infNFe").Element("ide").Element("cUF").Value
};
The whole XML loads into document (checked) but NFe.cuf gives me nothing. I guess the parameters inside the nodes are messing it up..
How do I get this "cuf" with linq?
What if I wanted the Id parameter in infNFe ?
© Stack Overflow or respective owner