Copy TAG specific XML file and merge with another XML file

0

Situation: - I need a single XML file that contains the data of all the other existing files and the ones that are to come. But I can not 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

    
asked by anonymous 25.11.2018 / 01:40

1 answer

0

I was able to do it simply using XPathNavigator in C #. In this case I'm putting nf along with a general notes.xml file where all the invoices are.

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();
        }
    
28.11.2018 / 19:39