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
<PackageReference Include="Greeva.Ubl.Validator" Version="1.0.5" />
<PackageVersion Include="Greeva.Ubl.Validator" Version="1.0.5" />
<PackageReference Include="Greeva.Ubl.Validator" />
paket add Greeva.Ubl.Validator --version 1.0.5
#r "nuget: Greeva.Ubl.Validator, 1.0.5"
#:package Greeva.Ubl.Validator@1.0.5
#addin nuget:?package=Greeva.Ubl.Validator&version=1.0.5
#tool nuget:?package=Greeva.Ubl.Validator&version=1.0.5
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
Related Packages
- 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 | 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
- 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.