Copy specific XML file TAG and merge with another XML file

Asked

Viewed 200 times

0

Situation: - I need a single XML file that contains the data of all other existing and upcoming files. But I can’t just join one file with the other and I just need a specific tag.

Is there any way to do this in C# or Java?

Help

  • Yes, it is possible in both Java and C#. It is just not possible to contain the data of the files that are still to come... Present the code of how you are trying to perform this merge.

1 answer

0


I managed to do it in a simple way using Xpathnavigator in C#. In this case I’m putting nf together with a notasGeral.xml file where all the tax notes are located.

private void button2_Click(object sender, EventArgs e)
        {
            XmlDocument document = new XmlDocument();
            document.Load("nf1.xml");
            XPathNavigator navigator = document.CreateNavigator();
            navigator.MoveToChild("nfeProc", "http://www.portalfiscal.inf.br/nfe");

            XPathDocument newBooks = new XPathDocument("C:\\Program Files\\VertrigoServ\\www\\Prototipo\\notasGeral.xml");
            XPathNavigator newBooksNavigator = newBooks.CreateNavigator();
            newBooksNavigator.MoveToChild("nfeProc", "");

            foreach (XPathNavigator nav in newBooksNavigator.SelectDescendants("NFe", "http://www.portalfiscal.inf.br/nfe", false))
            {
                navigator.AppendChild(nav);
            }

            document.Save("C:\\Program Files\\VertrigoServ\\www\\Prototipo\\notasGeral.xml");
            label1.Text = ("Concluído!");
            textBox1.Clear();
        }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.