Java library for creating and signing XML files based on UBL standards.
XBuilder can be found in Maven Central
Open your pom.xml file and add:
<dependency>
<groupId>io.github.project-openubl</groupId>
<artifactId>xbuilder</artifactId>
<version>1.1.0.Final</version>
</dependency>Open your build.gradle file and add:
compilegroup: 'io.github.project-openubl', name: 'xbuilder', version: '1.1.0.Final'- Perú
If you want support for your country please create an issue.
XML files can be created from Input Models; for instance:
InvoiceInputModelinput = InvoiceInputModel.Builder.anInvoiceInputModel()
.withSerie("F001")
.withNumero(1)
.withProveedor(ProveedorInputModel.Builder.aProveedorInputModel()
.withRuc("12345678912")
.withRazonSocial("Softgreen S.A.C.")
.build()
)
.withCliente(ClienteInputModel.Builder.aClienteInputModel()
.withNombre("Carlos Feria")
.withNumeroDocumentoIdentidad("12121212121")
.withTipoDocumentoIdentidad(Catalog6.RUC.toString())
.build()
)
.withDetalle(Arrays.asList(
DocumentLineInputModel.Builder.aDocumentLineInputModel()
.withDescripcion("Item1")
.withCantidad(newBigDecimal(10))
.withPrecioUnitario(newBigDecimal(100))
.withUnidadMedida("KGM")
.build(),
DocumentLineInputModel.Builder.aDocumentLineInputModel()
.withDescripcion("Item2")
.withCantidad(newBigDecimal(10))
.withPrecioUnitario(newBigDecimal(100))
.withUnidadMedida("KGM")
.build())
)
.build();
// Process Input and get XMLDocumentWrapper<InvoiceOutputModel> result = DocumentFacade.createXML(input, config, systemClock);
InvoiceOutputModeloutput = result.getOutput();
Stringxml = result.getXml();After you created the xml file you can now sign it:
Stringxml;
StringsignID = "mySignID";
// Get your certificate using the method of your preferenceX509Certificatecertificate;
PrivateKeyprivateKey;
DocumentsignedXML = XMLSigner.signXML(xml, signID, certificate, privateKey);