Edit Xml c file#

I'm having a little difficulty editing an xml.

I get the following xml:

<cteProc xmlns="http://www.portalfiscal.inf.br/cte" versao="3.00"> 
    <CTe CTemlns="http://www.portalfiscal.inf.br/cte">
        <infCte versao="3.00" Id="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx">
            <compl>Preciso inserir uma estrutura aqui!</compl>
        </infCte>
    </CTe>
</cteProc>

Between the tags <compl> </compl> I need to insert the following structure.

<ObsCont xCampo="vContainer"><xTexto>valor</xTexto></ObsCont>

I tried editing with the following code.

var xdoc = XDocument.Load(@"C:\ArquivosXML\" + integracao.NOME + ".xml");
       xdoc.Root.Add(xdoc.Element("Cte"), xdoc.Element("compl"),
           new XElement("ObsCont",
               new XAttribute("xCampo", "vContainer"),
               new XElement("xTexto", "valor")
               )
       );
       xdoc.Save(@"C:\ArquivosXML\" + integracao.NOME + ".xml");

With the above code I can insert more between the tags <cteProc> </cteProc>

And when I insert the element ObsCont is saving <ObsCont xmlns= "" xCampo="vContainer"> the correct is <ObsCont xCampo="vContainer"> without xmlns= "".

 0
Author: Augusto Vasques, 2019-07-23

1 answers

You can put one .Replace ("xmlns=\"","");

I have worked with electronic invoice and used a lot of replace in some specific situations.

 0
Author: Rafaela Marraschi, 2019-07-24 12:32:40