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
<PackageReference Include="Yamgooo.SRI.Xml" Version="1.0.2" />
<PackageVersion Include="Yamgooo.SRI.Xml" Version="1.0.2" />
<PackageReference Include="Yamgooo.SRI.Xml" />
paket add Yamgooo.SRI.Xml --version 1.0.2
#r "nuget: Yamgooo.SRI.Xml, 1.0.2"
#:package Yamgooo.SRI.Xml@1.0.2
#addin nuget:?package=Yamgooo.SRI.Xml&version=1.0.2
#tool nuget:?package=Yamgooo.SRI.Xml&version=1.0.2
SRI XML Service
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
(rootfactura
v1.1.0)InfoTributaria
InfoFactura
Detalles
/Detalle
ImpuestosDetalle
/ImpuestoDetalle
TotalConImpuestos
/TotalImpuesto
Pagos
/Pago
InfoAdicional
,Retenciones
(optional)
๐ง Validation rules (summary)
InfoTributaria
: requiredAmbiente
,TipoEmision
,RazonSocial
,Ruc
,ClaveAcceso
,Estab
,PtoEmi
,Secuencial
,DirMatriz
.InfoFactura
: requiredFechaEmision
,TipoIdentificacionComprador
,RazonSocialComprador
,IdentificacionComprador
. Values > 0 forTotalSinImpuestos
andImporteTotal
. At least onePago
.Detalles
: at least oneDetalle
withCodigoPrincipal
,Descripcion
;Cantidad
,PrecioUnitario
andPrecioTotalSinImpuesto
> 0; at least one tax inImpuestos
.
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
andStringWriter
- 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
- Fork
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit (
git commit -m "feat: amazing feature"
) - Push (
git push origin feature/amazing-feature
) - 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 | Versions 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. |
-
net8.0
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.