|
2 | 2 | [](https://sonarcloud.io/dashboard?id=project-openubl_xml-builder-lib)
|
3 | 3 | [](https://app.fossa.com/projects/git%2Bgithub.com%2Fcarlosthe19916%2Fxml-builder-lib?ref=badge_shield)
|
4 | 4 |
|
5 |
| -# xml-builder-lib |
| 5 | +# XML Builder Library |
| 6 | + |
| 7 | +Java library for creating XML files based on UBL standards. |
| 8 | + |
| 9 | +## Supported countries |
| 10 | + |
| 11 | +- Perú |
| 12 | + |
| 13 | +> If you want support for your country please create an issue. |
| 14 | +
|
| 15 | +## Getting started |
| 16 | + |
| 17 | +XML files can be created from Input Models; for instance: |
| 18 | + |
| 19 | +```java |
| 20 | +InvoiceInputModel input = InvoiceInputModel.Builder.anInvoiceInputModel() |
| 21 | + .withSerie("F001") |
| 22 | + .withNumero(1) |
| 23 | + .withProveedor(ProveedorInputModel.Builder.aProveedorInputModel() |
| 24 | + .withRuc("12345678912") |
| 25 | + .withRazonSocial("Softgreen S.A.C.") |
| 26 | + .build() |
| 27 | + ) |
| 28 | + .withCliente(ClienteInputModel.Builder.aClienteInputModel() |
| 29 | + .withNombre("Carlos Feria") |
| 30 | + .withNumeroDocumentoIdentidad("12121212121") |
| 31 | + .withTipoDocumentoIdentidad(Catalog6.RUC.toString()) |
| 32 | + .build() |
| 33 | + ) |
| 34 | + .withDetalle(Arrays.asList( |
| 35 | + DocumentLineInputModel.Builder.aDocumentLineInputModel() |
| 36 | + .withDescripcion("Item1") |
| 37 | + .withCantidad(new BigDecimal(10)) |
| 38 | + .withPrecioUnitario(new BigDecimal(100)) |
| 39 | + .withUnidadMedida("KGM") |
| 40 | + .build(), |
| 41 | + DocumentLineInputModel.Builder.aDocumentLineInputModel() |
| 42 | + .withDescripcion("Item2") |
| 43 | + .withCantidad(new BigDecimal(10)) |
| 44 | + .withPrecioUnitario(new BigDecimal(100)) |
| 45 | + .withUnidadMedida("KGM") |
| 46 | + .build()) |
| 47 | + ) |
| 48 | + .build(); |
| 49 | + |
| 50 | +// Process Input and get XML |
| 51 | +DocumentWrapper<InvoiceOutputModel> result = DocumentFacade.createXML(input, config, systemClock); |
| 52 | +InvoiceOutputModel output = result.getOutput(); |
| 53 | +String xml = result.getXml(); |
| 54 | +``` |
| 55 | + |
| 56 | +## Sign XMLs |
| 57 | + |
| 58 | +After you created the `xml` file you can now sign it: |
| 59 | + |
| 60 | +```java |
| 61 | +String xml; |
| 62 | +String signID = "mySignID"; |
| 63 | + |
| 64 | +// Get your certificate using the method of your preference |
| 65 | +X509Certificate certificate; |
| 66 | +PrivateKey privateKey; |
| 67 | + |
| 68 | +Document signedXML = XMLSigner.signXML(xml, signID, certificate, privateKey); |
| 69 | +``` |
0 commit comments