Beispiel #1
0
        public static InvoiceType UBLDeserialize(string oXmlFilePath)
        {
            // Please change the paths if you have a local copy of the UBL zip package (remote download is slow)
            //string xsdFilename = @"UBL-Invoice-2.1.xsd";
            string      xsdFilename = @"/maindoc/UBL-Invoice-2.1.xsd";
            string      xmlFilename = oXmlFilePath;
            InvoiceType invoice     = null;

            using (FileStream fs = File.OpenRead(xmlFilename))
            {
                // Validation
                XDocument xmlInvoice = XDocument.Load(fs);
                if (!ValidateUblDocument(xmlInvoice, xsdFilename))
                {
                    Console.WriteLine("Invalid document. Unable to continue");
                }

                // Load xml into an UBL Larsen invoice instance
                XmlSerializer xs = new XmlSerializer(typeof(InvoiceType));
                fs.Position = 0;
                invoice     = (InvoiceType)xs.Deserialize(fs);
            }

            //Show some values from the invoice
            if (invoice != null)
            {
                //Console.WriteLine("Invoice id: {0}", invoice.ID.Value);
                //Console.WriteLine("Issue date: {0}", invoice.IssueDate.Value.ToShortDateString());
                //Console.WriteLine("  Due Date: {0}", invoice.PaymentMeans[0].PaymentDueDate.Value.ToShortDateString());
                //Console.WriteLine("Amount due: {0} ({1})", invoice.LegalMonetaryTotal.PayableAmount.Value, invoice.LegalMonetaryTotal.PayableAmount.currencyID);
            }

            return(invoice.IsNull() ? null : invoice);
        }
Beispiel #2
0
        public static InvoiceType UBLDeserializeFromXml(string oXML)
        {
            // Please change the paths if you have a local copy of the UBL zip package (remote download is slow)
            //string xsdFilename = @"UBL-Invoice-2.1.xsd";
            string      StartPath   = Environment.CurrentDirectory;
            string      xsdFilename = StartPath + @"/maindoc/UBL-Invoice-2.1.xsd";
            InvoiceType invoice     = null;

            // Validation
            XDocument xmlInvoice = XDocument.Parse(oXML);
            //if (!ValidateUblDocument(xmlInvoice, xsdFilename))
            //{
            //    Console.WriteLine("Invalid document. Unable to continue");
            //}

            // Load xml into an UBL Larsen invoice instance


            TextReader oRead = new StringReader(oXML);

            using (XmlReader reader = XmlReader.Create(oRead))
            {
                Type          typeToSerialize = typeof(InvoiceType);
                XmlSerializer xs = new XmlSerializer(typeToSerialize);
                invoice = (InvoiceType)xs.Deserialize(reader);
            }

            //Show some values from the invoice
            if (invoice != null)
            {
                //Console.WriteLine("Invoice id: {0}", invoice.ID.Value);
                //Console.WriteLine("Issue date: {0}", invoice.IssueDate.Value.ToShortDateString());
                //Console.WriteLine("  Due Date: {0}", invoice.PaymentMeans[0].PaymentDueDate.Value.ToShortDateString());
                //Console.WriteLine("Amount due: {0} ({1})", invoice.LegalMonetaryTotal.PayableAmount.Value, invoice.LegalMonetaryTotal.PayableAmount.currencyID);
            }

            return(invoice.IsNull() ? null : invoice);
        }