Yamgooo.SRI.Xml 1.0.2

dotnet add package Yamgooo.SRI.Xml --version 1.0.2
                    
NuGet\Install-Package Yamgooo.SRI.Xml -Version 1.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Yamgooo.SRI.Xml" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Yamgooo.SRI.Xml" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Yamgooo.SRI.Xml" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Yamgooo.SRI.Xml --version 1.0.2
                    
#r "nuget: Yamgooo.SRI.Xml, 1.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Yamgooo.SRI.Xml@1.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Yamgooo.SRI.Xml&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Yamgooo.SRI.Xml&version=1.0.2
                    
Install as a Cake Tool

SRI XML Service

.NET License NuGet

A .NET library to generate and parse Ecuador SRI electronic invoice XML in the official format accepted by SRI (Factura v1.1.0). Use it to produce compliant XML for submission and to map existing SRI XML into strongly typed models.

In addition to XML serialization/deserialization, this package provides first-class C# domain models that map 1:1 to SRI specification artifacts (e.g., factura, infoTributaria, infoFactura, detalles, impuestos). These models encapsulate SRI-required fields, datatypes, and structural rules so that your application can work in a strongly-typed way against the normative XML schemas while leveraging validation helpers and compliant formatting.

Note: Digital signature (XAdES) is out of scope of this package. For signing, use Yamgooo.SRI.Sign alongside this library.

Also available in Spanish: README_es.md

๐Ÿš€ Features

  • XML Generation: Robust serialization with XmlSerializer, formatted UTF-8 output with indentation and clean namespaces
  • Deserialization: Safe conversion from XML to strongly-typed models
  • Validation: Pre-generation structural validation with detailed messages
  • SRI Models: Complete, strongly-typed C# models mirroring SRI Factura v1.1.0 (e.g., SriInvoice, InfoTributaria, InfoFactura, Detalles, impuestos, pagos). Designed to reflect official XML structure and constraints
  • Async: Async methods for non-blocking operations
  • Logging: Integration with Microsoft.Extensions.Logging
  • Error Handling: Clear exceptions and helpful traces

๐Ÿ“ฆ Installation

NuGet Package

dotnet add package Yamgooo.SRI.Xml

Manual Installation

git clone https://github.com/yamgooo/Sri.Xml.git
cd Sri.Xml
dotnet build

๐Ÿ› ๏ธ Quick Start

1) Register the service (DI)

using Microsoft.Extensions.DependencyInjection;
using Yamgooo.SRI.Xml;

var services = new ServiceCollection();

// Register the service
services.AddLogging();
services.AddSriXmlService();

var provider = services.BuildServiceProvider();
var sriXml = provider.GetRequiredService<ISriXmlService>();

2) Generate invoice XML

using Yamgooo.SRI.Xml.Models;

var invoice = new SriInvoice
{
    InfoTributaria = new InfoTributaria
    {
        Ambiente = "2",                // 1=Testing, 2=Production
        TipoEmision = "1",             // 1=Normal
        RazonSocial = "My Company S.A.",
        Ruc = "1790012345001",
        ClaveAcceso = "1234567890123456789012345678901234567890123456789",
        Estab = "001",
        PtoEmi = "001",
        Secuencial = "000000123",
        DirMatriz = "123 Evergreen Ave"
    },
    InfoFactura = new InfoFactura
    {
        FechaEmision = "09/01/2025",
        TipoIdentificacionComprador = "05", // National ID
        RazonSocialComprador = "John Doe",
        IdentificacionComprador = "0912345678",
        TotalSinImpuestos = 100.00m,
        ImporteTotal = 112.00m,
        TotalConImpuestos = new TotalConImpuestos
        {
            TotalImpuesto =
            {
                new TotalImpuesto
                {
                    Codigo = "2",            // VAT
                    CodigoPorcentaje = "2",  // 12%
                    BaseImponible = 100.00m,
                    Valor = 12.00m
                }
            }
        },
        Pagos = new Pagos
        {
            Pago = { new Pago { FormaPago = "01", Total = 112.00m } }
        }
    },
    Detalles = new Detalles
    {
        Detalle =
        {
            new Detalle
            {
                CodigoPrincipal = "SKU-001",
                Descripcion = "Sample product",
                Cantidad = 1,
                PrecioUnitario = 100.00m,
                Descuento = 0,
                PrecioTotalSinImpuesto = 100.00m,
                Impuestos = new ImpuestosDetalle
                {
                    Impuesto =
                    {
                        new ImpuestoDetalle
                        {
                            Codigo = "2",
                            CodigoPorcentaje = "2",
                            Tarifa = 12.00m,
                            BaseImponible = 100.00m,
                            Valor = 12.00m
                        }
                    }
                }
            }
        }
    }
};

var xml = await sriXml.GenerateInvoiceXmlAsync(invoice);

3) Deserialize invoice XML

var invoiceModel = await sriXml.DeserializeInvoiceXmlAsync(xml);

4) Validate structure before generating

var validation = sriXml.ValidateInvoiceStructure(invoice);
if (!validation.IsValid)
{
    Console.WriteLine($"Errors: {validation.ErrorMessage}");
}

๐Ÿ“‹ API Reference

ISriXmlService Interface

Task<string> GenerateInvoiceXmlAsync(SriInvoice invoice);
Task<SriInvoice> DeserializeInvoiceXmlAsync(string xmlContent);
ValidationResult ValidateInvoiceStructure(SriInvoice invoice);
string GenerateAccessKeyFromSriInvoice(SriInvoice invoice);

Main model classes (Yamgooo.SRI.Xml.Models)

  • SriInvoice (root factura v1.1.0)
  • InfoTributaria
  • InfoFactura
  • Detalles / Detalle
  • ImpuestosDetalle / ImpuestoDetalle
  • TotalConImpuestos / TotalImpuesto
  • Pagos / Pago
  • InfoAdicional, Retenciones (optional)

๐Ÿ”ง Validation rules (summary)

  • InfoTributaria: required Ambiente, TipoEmision, RazonSocial, Ruc, ClaveAcceso, Estab, PtoEmi, Secuencial, DirMatriz.
  • InfoFactura: required FechaEmision, TipoIdentificacionComprador, RazonSocialComprador, IdentificacionComprador. Values > 0 for TotalSinImpuestos and ImporteTotal. At least one Pago.
  • Detalles: at least one Detalle with CodigoPrincipal, Descripcion; Cantidad, PrecioUnitario and PrecioTotalSinImpuesto > 0; at least one tax in Impuestos.

Errors are exposed via ValidationResult.Errors and ValidationResult.ErrorMessage.

๐Ÿงช Testing

using Microsoft.Extensions.Logging;
using Moq;
using Yamgooo.SRI.Xml;

[Test]
public async Task GenerateInvoiceXmlAsync_MinValid_ReturnsXml()
{
    var mockLogger = new Mock<ILogger<SriXmlService>>();
    var service = new SriXmlService(mockLogger.Object);

    var invoice = /* build a valid object like the example */;

    var xml = await service.GenerateInvoiceXmlAsync(invoice);

    Assert.IsFalse(string.IsNullOrWhiteSpace(xml));
}

๐Ÿš€ Performance

  • Async I/O operations
  • Efficient writing with XmlWriter and StringWriter
  • UTF-8 output with indentation

๐Ÿ“ฆ Dependencies

  • .NET 8.0 (TargetFramework)
  • Microsoft.Extensions.Logging.Abstractions (logging)

๐Ÿ”’ Considerations

  • Validate business rules and SRI formats before submission
  • Avoid logging sensitive data (RUC, access keys)

๐Ÿค Contributing

  1. Fork
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit (git commit -m "feat: amazing feature")
  4. Push (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“„ License

MIT. See LICENSE.

๐Ÿ“ž Support

  • Issues: https://github.com/yamgooo/Sri.Xml/issues
  • Docs: https://github.com/yamgooo
  • Email: erikportillapesantez@outlook.com

Made with โค๏ธ for the Ecuadorian developer community

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.2 131 8/11/2025
1.0.1 124 8/11/2025
1.0.0 121 8/11/2025