I have the following sample XML file:
<?xml version="1.0" encoding="UTF-8"?>
<EnviarLoteRpsEnvio xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.abrasf.org.br/nfse">
<LoteRps Id="Lote4">
<NumeroLote>4</NumeroLote>
<Cnpj>07160720000111</Cnpj>
<QuantidadeRps>1</QuantidadeRps>
<ListaRps>
<Rps xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.abrasf.org.br/nfse">
<InfRps Id="Rps0716072000016300500787">
<Prestador>
<Cnpj>07160720000222</Cnpj>
</Prestador>
<Tomador>
<IdentificacaoTomador>
<CpfCnpj>
<Cnpj>07160720000333</Cnpj>
</CpfCnpj>
</IdentificacaoTomador>
</Tomador>
</InfRps>
</Rps>
</ListaRps>
</LoteRps>
My goal is to obtain the information of each Cnpj TAG separately so that I can identify them as Cnpj of the RPS, the Provider and the Policyholder.
I've already managed to get the first Cnpj of XML with this code C#
private void btnLerTag_Click(object sender, EventArgs e)
{
//Busca o primeiro CNPJ do XML
XmlDocument doc = new XmlDocument();
string ArquivoXML = txtCaminhoXML.Text;
doc.Load(ArquivoXML);
XmlNode root = doc.DocumentElement;
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("n", "http://www.abrasf.org.br/nfse");
XmlNode node = root.SelectSingleNode("//n:Cnpj", nsmgr);
foreach (XmlNode oNo in node)
{
lstXML.Items.Add(node.InnerXml);
}
}
Can anyone give me any suggestions to solve this problem?