-4

I have an XML file like this:

<billing_documents>
    <billing_document>
        <Field1>AAAAA</Field1>
        <Field2>BBBBB</Field2>
        <Field3>20180731</Field3>
        <Field4/>
    <billing_document>
<billing_documents>

(some field could be empty, like Field4 in this example),

and I need to read it and save the "FieldX" values in a Oracle table that has the same structure.

Field1 - Field2 - Field3 - Field4

Can anyone help me?

Thanks a lot in advance.

Luis

PS I'm using Visual Studio 2017.

Ciupaz
  • 639
  • 1
  • 10
  • 19
  • this could help to do the ferst part [How do I read and parse an XML file in C#?](https://stackoverflow.com/questions/642293/how-do-i-read-and-parse-an-xml-file-in-c) – hotfix Aug 24 '18 at 08:51

1 Answers1

1

Try using xml linq. I put results into a datatable. You can modify as necessary to store results in oracle database

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using System.Data;

namespace ConsoleApplication1
{
    public class Program
    {
        const string FILENAME = @"c:\temp\test.xml";
        private static void Main()
        {
            XDocument doc = XDocument .Load(FILENAME);

            DataTable dt = new DataTable();
            dt.Columns.Add("Field1", typeof(string));
            dt.Columns.Add("Field2", typeof(string));
            dt.Columns.Add("Field3", typeof(string));
            dt.Columns.Add("Field4", typeof(string));

            foreach (XElement document in doc.Descendants("billing_document"))
            {
                dt.Rows.Add(new object[] {
                    (string)document.Element("Field1"),
                    (string)document.Element("Field2"),
                    (string)document.Element("Field3"),
                    (string)document.Element("Field4")
                });
            }
        }

    }

}
jdweng
  • 33,250
  • 2
  • 15
  • 20