Greeva.Ubl.Validator 1.0.5

dotnet add package Greeva.Ubl.Validator --version 1.0.5
                    
NuGet\Install-Package Greeva.Ubl.Validator -Version 1.0.5
                    
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="Greeva.Ubl.Validator" Version="1.0.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Greeva.Ubl.Validator" Version="1.0.5" />
                    
Directory.Packages.props
<PackageReference Include="Greeva.Ubl.Validator" />
                    
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 Greeva.Ubl.Validator --version 1.0.5
                    
#r "nuget: Greeva.Ubl.Validator, 1.0.5"
                    
#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 Greeva.Ubl.Validator@1.0.5
                    
#: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=Greeva.Ubl.Validator&version=1.0.5
                    
Install as a Cake Addin
#tool nuget:?package=Greeva.Ubl.Validator&version=1.0.5
                    
Install as a Cake Tool

Greeva.Ubl.Validator

UBL XML schema validation for Greeva electronic invoicing documents with embedded XSD schemas.

Overview

Greeva.Ubl.Validator provides comprehensive XML schema validation for UBL (Universal Business Language) documents according to SUNAT specifications. It includes embedded XSD schemas for both UBL 2.0 and UBL 2.1 standards.

Key Features

  • UBL 2.0 & 2.1 Support: Complete schema validation for both UBL versions
  • Embedded XSD Schemas: All schemas embedded as resources - no external files needed
  • SUNAT Extensions: Includes Peru-specific UBL extensions (UBLPE)
  • Document Type Support: Invoice, CreditNote, DebitNote, DespatchAdvice, Summary, Voided
  • Comprehensive Validation: Structure, data types, and business rules validation
  • Digital Signature Schemas: XML DSig validation schemas included

Supported Document Types

UBL 2.1 Documents

  • Invoice: Electronic invoices
  • CreditNote: Credit notes
  • DebitNote: Debit notes
  • DespatchAdvice: Despatch guides
  • ApplicationResponse: CDR responses
  • SelfBilledInvoice: Self-billed invoices
  • SelfBilledCreditNote: Self-billed credit notes

UBL 2.0 Documents (Legacy)

  • Invoice: Electronic invoices
  • CreditNote: Credit notes
  • DebitNote: Debit notes
  • DespatchAdvice: Despatch guides
  • SummaryDocuments: Daily summaries
  • VoidedDocuments: Voided documents
  • Perception: Perception documents
  • Retention: Retention documents
  • ApplicationResponse: CDR responses

Usage

Basic Validation

using Greeva.Ubl.Validator;

// Create validator
var validator = new UblValidation();

// Validate XML content
string xmlContent = "<?xml version='1.0'?>..."; // Your UBL XML
var result = validator.Validate(xmlContent, UblVersion.UblVersion21);

if (result.IsValid)
{
    Console.WriteLine("✅ XML is valid");
}
else
{
    Console.WriteLine("❌ XML validation failed:");
    foreach (var error in result.Errors)
    {
        Console.WriteLine($"  - {error}");
    }
}

Document-Specific Validation

// Validate Invoice
var invoiceResult = validator.ValidateInvoice(xmlContent, UblVersion.UblVersion21);

// Validate Credit Note
var creditNoteResult = validator.ValidateCreditNote(xmlContent, UblVersion.UblVersion21);

// Validate Despatch Advice
var despatchResult = validator.ValidateDespatchAdvice(xmlContent, UblVersion.UblVersion21);

Validation with Schema Details

var validationContent = new UblValidationContent
{
    XmlContent = xmlContent,
    Version = UblVersion.UblVersion21,
    DocumentType = UblDocumentType.Invoice
};

var result = validator.ValidateDocument(validationContent);

if (!result.IsValid)
{
    Console.WriteLine($"Validation failed for {result.DocumentType}:");
    Console.WriteLine($"Schema: {result.SchemaPath}");
    
    foreach (var error in result.Errors)
    {
        Console.WriteLine($"Line {error.LineNumber}: {error.Message}");
    }
}

UBL Versions

UBL 2.1 (Current Standard)

  • Namespace: urn:oasis:names:specification:ubl:schema:xsd:Invoice-2
  • Features: Enhanced metadata, better structure
  • Recommended: For new implementations

UBL 2.0 (Legacy)

  • Namespace: urn:oasis:names:specification:ubl:schema:xsd:Invoice-2
  • Features: Basic UBL implementation
  • Usage: Legacy document support

Embedded Schemas

The package includes complete XSD schema sets:

UBL 2.1 Schemas

Xsd/2.1/common/
├── CCTS_CCT_SchemaModule-2.1.xsd
├── UBL-CommonAggregateComponents-2.1.xsd
├── UBL-CommonBasicComponents-2.1.xsd
├── UBL-CommonExtensionComponents-2.1.xsd
├── UBL-CommonSignatureComponents-2.1.xsd
└── ... (additional common schemas)

Xsd/2.1/maindoc/
├── UBL-Invoice-2.1.xsd
├── UBL-CreditNote-2.1.xsd
├── UBL-DebitNote-2.1.xsd
├── UBL-DespatchAdvice-2.1.xsd
└── ... (additional document schemas)

UBL 2.0 Schemas + SUNAT Extensions

Xsd/2.0/common/
├── UBLPE-SunatAggregateComponents-1.1.xsd
├── UBL-CommonAggregateComponents-2.0.xsd
└── ... (UBL 2.0 schemas)

Xsd/2.0/maindoc/
├── UBL-Perception-2.0.xsd
├── UBL-Retention-2.0.xsd
├── UBL-SummaryDocuments-2.0.xsd
├── UBL-VoidedDocuments-2.0.xsd
└── ... (SUNAT-specific schemas)

Validation Results

UblValidationResult

public class UblValidationResult
{
    public bool IsValid { get; set; }
    public List<string> Errors { get; set; }
    public UblDocumentType DocumentType { get; set; }
    public UblVersion Version { get; set; }
    public string SchemaPath { get; set; }
}

Error Information

// Detailed error with line numbers
foreach (var error in result.DetailedErrors)
{
    Console.WriteLine($"Line {error.LineNumber}, Column {error.ColumnNumber}:");
    Console.WriteLine($"  Severity: {error.Severity}");
    Console.WriteLine($"  Message: {error.Message}");
    Console.WriteLine($"  Element: {error.ElementName}");
}

Advanced Usage

Custom Schema Resolution

var validator = new UblValidation();

// Configure custom schema resolver
validator.ConfigureSchemaResolver(schemaPath =>
{
    // Custom schema loading logic
    return LoadCustomSchema(schemaPath);
});

Validation Settings

var settings = new ValidationSettings
{
    ValidateStructure = true,
    ValidateDataTypes = true,
    ValidateBusinessRules = true,
    StrictMode = false // Allow SUNAT extensions
};

var result = validator.Validate(xmlContent, UblVersion.UblVersion21, settings);

Common Validation Errors

Namespace Issues

Error: The 'http://...' namespace is not declared
Solution: Ensure all required namespaces are declared in root element

Missing Required Elements

Error: Element 'cbc:ID' is required but missing
Solution: Add all mandatory UBL elements according to schema

Invalid Data Formats

Error: Invalid date format in 'cbc:IssueDate'
Solution: Use YYYY-MM-DD format for dates

Schema Validation

Error: Element 'CustomElement' is not allowed
Solution: Remove custom elements or use proper UBL extension points

Performance Considerations

  • Schema Caching: Schemas are loaded once and cached
  • Memory Usage: Embedded schemas increase initial memory footprint
  • Validation Speed: Fast validation after initial schema loading
  • Concurrent Access: Thread-safe validation operations

Integration with Greeva

// Validate before sending to SUNAT
var xml = await xmlBuilder.BuildAsync(invoice);

var validationResult = validator.ValidateInvoice(xml, UblVersion.UblVersion21);
if (!validationResult.IsValid)
{
    throw new InvalidOperationException($"Invalid XML: {string.Join(", ", validationResult.Errors)}");
}

// Proceed with signing and sending
var signedXml = await xmlSigner.SignXmlAsync(xml);
var result = await cpeService.SendBillAsync(fileName, zipContent);

Dependencies

  • .NET 8.0
  • System.Xml (built-in XML processing)
  • No external dependencies
  • Greeva.Core: Core domain models
  • Greeva.Xml: XML generation functionality
  • Greeva.Domain.Validator: Business rule validation
  • Greeva.WebApi: Web API integration with validation

License

MIT License - see LICENSE file for details.

Support

For issues and questions, please visit: https://github.com/augustoteles/greeva/issues

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.
  • net8.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Greeva.Ubl.Validator:

Package Downloads
Greeva.WebApi

Greeva library optimized for Web APIs with DI support and embedded templates

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.5 288 11/21/2025
1.0.4 423 11/18/2025
1.0.3 909 11/13/2025
1.0.1 160 10/24/2025
1.0.0 212 10/12/2025