Giter Club home page Giter Club logo

ph-ubl's Introduction

ph-ubl

Maven Central javadoc CodeCov

This is the readme file for version 5.x or later.

Set of Java libraries for reading and writing OASIS UBL 2.0, 2.1, 2.2, 2.3 and 2.4 documents. The following projects are contained:

  • ph-ubl-testfiles contains all UBL test files (used only in Maven test scope)
  • ph-ubl-api base library containing common stuff for UBL testing only.
  • ph-ubl20 contains the generated JAXB files for UBL 2.0 as well as the helper classes.
  • ph-ubl20-codelists contains the generated enums for the UBL 2.0 codelists (optional artefact)
  • ph-ubl21 contains the generated JAXB files for UBL 2.1 as well as the helper classes.
  • ph-ubl21-codelists contains the generated enums for the UBL 2.1 codelists (optional artefact)
  • ph-ubl22 contains the generated JAXB files for UBL 2.2 as well as the helper classes.
  • ph-ubl22-codelists contains the generated enums for the UBL 2.2 codelists (optional artefact)
  • ph-ubl23 contains the generated JAXB files for UBL 2.3 as well as the helper classes.
  • ph-ubl23-codelists contains the generated enums for the UBL 2.3 codelists (optional artefact)
  • ph-ubl24 contains the generated JAXB files for UBL 2.4 as well as the helper classes.
  • ph-ubl24-codelists contains the generated enums for the UBL 2.4 codelists (optional artefact)
  • ph-ubltr contains the generated JAXB files UBL-tr - the Turkish e-Invoice (optional artefact)
  • ph-ublpe contains the generated JAXB files for UBLPE #openinvoiceperu (optional artefact)
  • ph-ubl-dian contains the generated JAXB files for the Colombian e-Invoice (optional artefact)
  • ph-ubl-eforms contains the generated JAXB files for the EU eForms objects (optional artefact) - see https://ec.europa.eu/growth/single-market/public-procurement/digital-procurement/eforms_en

Building

This project requires Java 1.8 or higher to be build and used.

The JAXB generated sources are created dynamically via mvn process-sources and are not part of the committed source files. This is also automatically called when you call mvn clean install. The folders with the generated sources differ from subproject to subproject:

  • ph-ubl20: target\generated-sources\ubl20
  • ph-ubl21: target\generated-sources\ubl21
  • ph-ubl22: target\generated-sources\ubl22
  • ph-ubl23: target\generated-sources\ubl23
  • ph-ubl24: target\generated-sources\ubl24
  • ph-ublpe: target\generated-sources\ublpe
  • ph-ubltr: target\generated-sources\ubltr
  • ph-ubl-dian: target\generated-sources\dian
  • ph-ubl-eforms: target\generated-sources\eforms

Examples

An example for reading and writing UBL 2.0 files can be found in the test file UBL20FuncTest.java. An example to create an invoice from scratch can be found in the test code CreateInvoiceFromScratchFuncTest.java.

An example for reading and writing UBL 2.1 files can be found in the test file UBL21FuncTest.java. An example to create an invoice from scratch can be found in the test code CreateInvoiceFromScratchFuncTest.java.

Maven usage generic

You can use ph-ubl as a BOM (bill of material) when you include the following in the dependencyManagement section of your POM, replacing x.y.z with the effective version number:

<dependency>
  <groupId>com.helger.ubl</groupId>
  <artifactId>ph-ubl-parent-pom</artifactId>
  <version>x.y.z</version>
  <type>pom</type>
  <scope>import</scope>
</dependency>

Note: prior to v6.3.0 the Maven groupId was com.helger.

Maven usage UBL 2.0

To read and write UBL 2.0 documents add the following to your pom.xml to use this artifact:

<dependency>
  <groupId>com.helger.ubl</groupId>
  <artifactId>ph-ubl20</artifactId>
  <version>x.y.z</version>
</dependency>

To also use the generated enums for the UBL 2.0 codelists add the following artifact:

<dependency>
  <groupId>com.helger.ubl</groupId>
  <artifactId>ph-ubl20-codelists</artifactId>
  <version>x.y.z</version>
</dependency>

Note: prior to v6.3.0 the Maven groupId was com.helger.

Maven usage UBL 2.1

To read and write UBL 2.1 documents add the following to your pom.xml to use this artifact:

<dependency>
  <groupId>com.helger.ubl</groupId>
  <artifactId>ph-ubl21</artifactId>
  <version>x.y.z</version>
</dependency>

To also use the generated enums for the UBL 2.1 codelists add the following artifact:

<dependency>
  <groupId>com.helger.ubl</groupId>
  <artifactId>ph-ubl21-codelists</artifactId>
  <version>x.y.z</version>
</dependency>

Note: prior to v6.3.0 the Maven groupId was com.helger.

Maven usage UBL 2.2

To read and write UBL 2.2 documents add the following to your pom.xml to use this artifact:

<dependency>
  <groupId>com.helger.ubl</groupId>
  <artifactId>ph-ubl22</artifactId>
  <version>x.y.z</version>
</dependency>

To also use the generated enums for the UBL 2.2 codelists add the following artifact:

<dependency>
  <groupId>com.helger.ubl</groupId>
  <artifactId>ph-ubl22-codelists</artifactId>
  <version>x.y.z</version>
</dependency>

Note: prior to v6.3.0 the Maven groupId was com.helger.

Maven usage UBL 2.3

To read and write UBL 2.3 documents add the following to your pom.xml to use this artifact:

<dependency>
  <groupId>com.helger.ubl</groupId>
  <artifactId>ph-ubl23</artifactId>
  <version>x.y.z</version>
</dependency>

To also use the generated enums for the UBL 2.3 codelists add the following artifact:

<dependency>
  <groupId>com.helger.ubl</groupId>
  <artifactId>ph-ubl23-codelists</artifactId>
  <version>x.y.z</version>
</dependency>

Note: prior to v6.3.0 the Maven groupId was com.helger.

Maven usage UBL 2.4

To read and write UBL 2.4 documents add the following to your pom.xml to use this artifact:

<dependency>
  <groupId>com.helger.ubl</groupId>
  <artifactId>ph-ubl24</artifactId>
  <version>x.y.z</version>
</dependency>

To also use the generated enums for the UBL 2.4 codelists add the following artifact:

<dependency>
  <groupId>com.helger.ubl</groupId>
  <artifactId>ph-ubl24-codelists</artifactId>
  <version>x.y.z</version>
</dependency>

Supported since v8.0.0

Maven usage UBL-tr

To read and write UBL-tr (http://www.ubltr.com/) documents add the following to your pom.xml to use this artifact:

<dependency>
  <groupId>com.helger.ubl</groupId>
  <artifactId>ph-ubltr</artifactId>
  <version>x.y.z</version>
</dependency>

Note: prior to v6.3.0 the Maven groupId was com.helger.

Maven usage UBL-PE

To read and write UBL-PE 2.0 documents add the following to your pom.xml to use this artifact:

<dependency>
  <groupId>com.helger.ubl</groupId>
  <artifactId>ph-ublpe</artifactId>
  <version>x.y.z</version>
</dependency>

Note: prior to v6.3.0 the Maven groupId was com.helger.

Maven usage Dian UBL

To read and write Dian UBL 2.1 documents add the following to your pom.xml to use this artifact:

<dependency>
  <groupId>com.helger.ubl</groupId>
  <artifactId>ph-ubl-dian</artifactId>
  <version>x.y.z</version>
</dependency>

Note: prior to v6.3.0 the Maven groupId was com.helger.

Maven usage eForms UBL

To read and write eForms UBL 2.3 documents add the following to your pom.xml to use this artifact:

<dependency>
  <groupId>com.helger.ubl</groupId>
  <artifactId>ph-ubl-eforms</artifactId>
  <version>x.y.z</version>
</dependency>

Supported since v6.7.0

Gradle considerations

Old versions of this project rely on JDK version based Maven profile activation. See https://github.com/phax/ph-jaxb-pom#gradle-usage for help on this specific issue.

Download

Binary versions of the artefacts can be downloaded from Maven Central:

Other UBL sites

For further information on the Universal Business Language can be found on the following pages:

News and noteworthy

  • v9.0.1 - 2024-03-28
    • Updated to ph-commons 11.1.5
    • Ensured Java 21 compatibility
  • v9.0.0 - 2024-03-04
    • Updated to UBL 2.4-CS01
    • Updated to eForms SDK 1.10.1
    • Switched JAXB Maven plugin to org.jvnet.jaxb:jaxb-maven-plugin
    • Removed deprecated classes and elements
    • Added new enum EUBL24DocumentType
  • v8.0.3 - 2023-07-31
    • Updated to ph-commons 11.1
  • v8.0.2 - 2023-04-30
    • Extended the UBL2(0|1|2|3|4)Marshaller classes with additional APIs to access the XSDs
  • v8.0.1 - 2023-04-28
    • Avoided the same name for the JAXB generated package for the unqualified datatypes in UBL 2.3 and 2.4
  • v8.0.0 - 2023-04-21
    • Added support for UBL 2.4-CSD01 - new submodules ph-ubl24 and ph-ubl24-codelists
    • Updated to ph-commons 11.0.3
    • New classes UBL2(0|1|2|3|4)Marshaller that can read, write and validate
    • Deprecated classes EUBL20DocumentType, UBL20DocumentType, UBL20(Reader|Validator|Writer) and UBL20(Reader|Validator|Writer)Builder
    • Moved the XML Schemas to a new path that starts with external/
    • By updating to ph-jaxb-plugin v4.0.2 an integrity error could be resolved
  • v7.0.0 - 2023-01-09
    • Using Java 11 as the baseline
    • Updated to ph-commons 11
    • Using JAXB 4.0 as the baseline
  • v6.7.0 - 2021-12-29
  • v6.6.3 - 2021-09-21
    • Updated to the final UBL 2.3 XML Schemas - no changes compared to CS01 except for comments
    • Updated dependencies, so that the date/time objects now implement Serializable and that date/time objects are allowed to have no second fractions. The same effect can be reached by explicitly using v6.6.2 with ph-commons 10.1.3
  • v6.6.2 - 2021-05-16
    • Removed all the default UBL XSDs for Xades, XMLDsig and CCTS to avoid confusion with the generic ones from the ph-xsds-* artefacts. This might be an incompatible change, if you reference the files in a JAXB ctaalog file.
  • v6.6.1 - 2021-05-13
    • Improved the handling for the Dian Extension and ensuring the "sts" namespace prefix is used.
  • v6.6.0 - 2021-05-02
    • Updated to ph-commons 10.1.0
    • Changed the JAXB binding for date time types XMLOffset(Date|Time|DateTime) - last change - sorry
  • v6.5.0 - 2021-03-21
    • Updated to ph-commons 10.0.0
    • Changed the JAXB binding for date time types Offset(Date|Time|DateTime)
  • v6.4.3 - 2021-02-11
  • v6.4.2 - 2020-12-18
  • v6.4.1 - 2020-09-17
    • Updated to Jakarta JAXB 2.3.3
  • v6.4.0 - 2020-08-30
  • v6.3.0 - 2020-05-26
    • Changed Maven groupId to com.helger.ubl
  • v6.2.1 - 2020-02-06
  • v6.2.0 - 2019-11-05
    • Added support for UBL 2.3 CSPRD01
  • v6.1.3 - 2019-10-17
    • Added classes UBL20InvoiceHelper, UBL20CreditNoteHelper, UBL21InvoiceHelper, UBL21CreditNoteHelper, UBL22InvoiceHelper and UBL22CreditNoteHelper to allow for easy "type conversion"
  • v6.1.2 - 2019-05-07
    • Added Java 12 support
  • v6.1.1 - 2019-01-26
    • The ph-ubl-jaxb-plugin was moved to ph-jaxb22-plugin and is discontinued in here
  • v6.1.0 - 2018-11-22
    • Requires at least ph-commons 9.2.0
  • v6.0.2 - 2018-07-17
  • v6.0.1 - 2018-04-03
    • Updated to UBL 2.2 CS 01
  • v6.0.0 - 2018-01-09
    • Binds to ph-commons 9.0.0
    • Added initial UBL 2.2 CSPRD02 support
    • Fixes issues #11
  • v5.1.0 - 2016-09-09
    • Binds to ph-commons 8.5.x
  • v5.0.3 - 2016-07-26
  • v5.0.1 - 2016-07-22
  • v5.0.0 - 2016-06-11
    • Binds to ph-commons 8.x
  • v4.5.0 - 2015-11-30
    • New API that this more flexible and contains less overloads - see the examples
    • Added the possibility to easily customize the namespace prefix mapping and other things
  • v4.0.0 - 2015-07-28
    • Restructured artefacts to use an "include on demand" instead of an "exclude on demand" pattern
    • Improved OSGI support

My personal Coding Styleguide | It is appreciated if you star the GitHub project if you like it.

ph-ubl's People

Contributors

phax avatar skinkie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ph-ubl's Issues

Extending library for customisations

Hello Philip!

First of all thanks for your great effort. I'm using this library for reading / writing UBL documents, also customised for "UBL Turkish Customization - UBLTR" documents.

Turkish customisation also comes with following documents

    PROCESS_USER_ACCOUNT (org.hr_xml._3.ProcessUserAccountType.class, "../HRXML/UserAccount.xsd"),
    STANDARD_BUSINESS_DOCUMENT (org.unece.cefact.namespaces.standardbusinessdocumentheader.StandardBusinessDocument.class, "PackageProxy.xsd"),
    PACKAGE (tr.gov.efatura.package_namespace.Package.class, "../common/Package.xsd");

My main problem is, Reader, Writer, Validator, Marshaller, and DocumentType(s) classes marked as final.

So, i can't extend any functionality and i need to write this classes separately (most of the parts derived from your work) e.g. class UBL21TRMarshaller extends AbstractUBLMarshaller.

Do you have any plan for making this classes extendible for using with UBL customisations?

Thanks!
O.

How to add UBLDocumentSignatures in UBL Extension?

I have created 1 UBL document InvoiceType. It has all the required details.
Now I want to add a Signature to the UBL document. The Extension will be used for this AFAIK.
I have tried to find out this but I am not able to find the solution.

I tried with xades4j but there's 1 issue, it creates a Signature directly in Document(using ds:Signature), not in the Extension. I passed the UBL XML string to xades4j.
I want it to be in structure:

<ext:UBLExtensions> <ext:UBLExtension> <ext:ExtensionURI>urn:oasis:names:specification:ubl:dsig:enveloped:xades</ext:ExtensionURI> <ext:ExtensionContent> <sig:UBLDocumentSignatures xmlns:sac="urn:oasis:names:specification:ubl:schema:xsd:SignatureAggregateComponents-2" xmlns:sbc="urn:oasis:names:specification:ubl:schema:xsd:SignatureBasicComponents-2" xmlns:sig="urn:oasis:names:specification:ubl:schema:xsd:CommonSignatureComponents-2"> <sac:SignatureInformation> <cbc:ID>urn:oasis:names:specification:ubl:signature:1</cbc:ID> <sbc:ReferencedSignatureID>urn:oasis:names:specification:ubl:signature:Invoice</sbc:ReferencedSignatureID> <ds:Signature Id="signature" xmlns:ds="http://www.w3.org/2000/09/xmldsig#"> <ds:SignedInfo>

Please suggest me way to add a signature in the UBL extension.

time Adapter

I have a question
in ph-ubl time (adpater with LocalTime) is it posislbe to get it marshalled with timezone ? like '13:24:00-05' ... it gets marshalled '13:24:00.213'

Regards

Error should be thrown/returned if not a valid document based on given schema

Hello @phax,
I am trying to learn UBL and used ph-ubl library to validate the Invoice XML document.
XML document is based on UBL 2.1.
Following is a sample code I have done:

public static void main(String[] args) {
    try {
        InvoiceType aUBLObject = UBL21Reader.invoice().read(ResourceUtils.getFile("classpath:UBL-Invoice-2.1-Example.xml"));
        if (aUBLObject != null) {
            IErrorList aErrors = UBL21Validator.invoice ().validate (aUBLObject);
            System.out.println(aErrors);
        }
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }
}

I have intentionally deleted cbc:ID from the input XML file(UBL-Invoice-2.1-Example.xml).
While reading XML on first-line aDoc will be null as cbc:ID is one of the mandatory fields as per schema.
It prints in the console that:
[SAX] cvc-complex-type.2.4.a: Invalid content was found starting with element 'cbc:IssueDate'. One of '{"urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2":CustomizationID, "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2":ProfileID, "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2":ProfileExecutionID, "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2":ID}' is expected. (org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'cbc:IssueDate'. One of '{"urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2":CustomizationID, "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2":ProfileID, "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2":ProfileExecutionID, "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2":ID}' is expected.)

How to catch this error as it just prints into the console. It should throw some error or return something so we can come to know that oh yes this is missing in input. I want to handle/collect errors if any in the input document.
Please guide/correct me if I making any mistakes.

eForms support

We are working on a preliminary implementation for handling invoices based on (TED) https://github.com/OP-TED/eForms-SDK. They've built their documents on the UBL23 standard. We'd like to use ph-ubl for reading and creating of the documents.

Are there any plans to support eForms? Maybe an extra package like you have for DIAN or PE?

Regards,

UBL 2.1 unused namespace

Dear,

First of all, thanks for your library.

I'm generating one invoice, but I noticed that one namespace is added without being used in the xml:

<?xml version="1.0" encoding="UTF-8"?>
<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" 
          xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
          xmlns:cec="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"
          xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">
    <cbc:UBLVersionID>2.1</cbc:UBLVersionID>
    ....
    ....
    
</Invoice>

The xmlns:cec="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" is added as namespace, but there is no reference of cec in the xml.

I'm saving the file using these lines:

var status = UBL21Writer.invoice().write(ublInvoice, file);

Is that a bug?

I'm using: JAVA 11 with ph-ubl 6.2.0

Thank you

ESuccess errors when debugging

I begin to test this library, and I noticed that UBL20Writer returns "FAILURE" but as far as I can see there is no hint what is maybe wrong with the invoice created.

How can I get some more verbose error output when it fails?

no prefix in document

Hello Phax

I want to ask you , how is it possible to have the document without the prefix, I mean
<Invoice xmlns=.... instead of <ns6:Invoice xmlns:ns6-........

Thank you

Generate Ubl

Hi, i saw that this library is usefull for write and read Ubl(existed) documents, but i can't find any class to GENERATE ubl documents, can i use this library for GENERATE Ubl, could you give me a suggestion please.

Java Object to UBL XML

I have a Java object which has been parsed from JSON(In my existing REST-based spring boot application). I want to convert this Java object to XML so currently, I am converting the Java object to related UBL Invoice/Credit/Debit/Self Billed Invoice.
I am writing code to manually transform my Java object to a related UBL document.
How can I convert that UBL document to XML without writing it into the file?

Do I need to convert it into a Document or is there any other way?
Is it possible to convert Documents to XML structure directly?
I need XML because I have to generate a hash of the document XML for further crypto processing.

Currently, I have added/converted data into the:
InvoiceType invoice = new InvoiceType();

Now I want to proceed further to generate standard UBL XML.

UBL 2.1 Tests not working

Some classes seem missing in UBL21Reading.java (branch master):

import oasis.names.specification.ubl.schema.xsd.applicationresponse_21.ApplicationResponseType;
import oasis.names.specification.ubl.schema.xsd.attacheddocument_21.AttachedDocumentType;
import oasis.names.specification.ubl.schema.xsd.awardednotification_21.AwardedNotificationType;
import oasis.names.specification.ubl.schema.xsd.billoflading_21.BillOfLadingType;
import oasis.names.specification.ubl.schema.xsd.callfortenders_21.CallForTendersType;
import oasis.names.specification.ubl.schema.xsd.catalogue_21.CatalogueType;
import oasis.names.specification.ubl.schema.xsd.cataloguedeletion_21.CatalogueDeletionType;
import oasis.names.specification.ubl.schema.xsd.catalogueitemspecificationupdate_21.CatalogueItemSpecificationUpdateType;
import oasis.names.specification.ubl.schema.xsd.cataloguepricingupdate_21.CataloguePricingUpdateType;
import oasis.names.specification.ubl.schema.xsd.cataloguerequest_21.CatalogueRequestType;
import oasis.names.specification.ubl.schema.xsd.certificateoforigin_21.CertificateOfOriginType;

....

how to change cbc:IssueTime formats

Hi,
How I can change cbc:IssueTime formats from cbc:IssueTime17:18:50.0</cbc:IssueTime>
to cbc:IssueTime17:18:50</cbc:IssueTime> whiteout nanosecond?

UBLExtension in InvoiceType with incorrect namespace prefix

Hi, first of all thanks for this API.

My issue is that when I create an InvoiceType document and added a UBLExtensions when is marshalled to DOM the namespace prefix appears as cec:

<cec:UBLExtensions xmlns:cec="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2">
<cec:UBLExtension>
<cec:ExtensionContent/>
</cec:UBLExtension>
</cec:UBLExtensions>

instead of the one used in the xsd for UBL-Invoice-2.0.xsd ext:

xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"

Any ideas ?

Problem with the type name XML (two classes have the same XML type name)

Hello there:

First of all, congratulation for your powerfull project. At this time I am trying to work with this in and Android application.

This has been done, but when I am trying to do the newInstance of the JAXBContext i recieved these errors

Two classes have the same XML type name "NameType". Use @XmlType.name and @XmlType.namespace to assign different names to them. this problem is related to the following location: at un.unece.uncefact.data.specification.unqualifieddatatypesschemamodule._2.NameType at oasis.names.specification.ubl.schema.xsd.commonbasiccomponents_2.NameType at protected oasis.names.specification.ubl.schema.xsd.commonbasiccomponents_2.NameType

I donยดt know if this happened to some of you. I am working with libraries customized to java android.

Thank you in advance.

LocationType

Hi Philip,
I have a problem for generate correctly the Delivery / DeliveryLocation (which is a LocationType).
Indeed, the LocationType class contains only a Language notion, and not an adress, id, description...
I work with frencyh financial administration and i have to generate this sequence :

<cac:Delivery>
  <cac:DeliveryLocation>
ย    <cbc:ID>Z3242</cbc:ID>
    <cbc:Description>Site numรฉro 1</cbc:Description>
 ย   <cac:Address>
   ย   <cbc:StreetName>2 avenue Charles de Gaulle</cbc:StreetName>
   ย   <cbc:CityName>Paris</cbc:CityName>
   ย   <cbc:PostalZone>75008</cbc:PostalZone>
   ย   <cac:Country>
     ย   <cbc:IdentificationCode>FR</cbc:IdentificationCode>
   ย   </cac:Country>
ย  </cac:Address>
 ย </cac:DeliveryLocation>
</cac:Delivery>

I use the ph-ubl21 / 5.1.0.

Thanks for your attention,

Pierre

Invoice xmlns prefix

I have followed the CreateInvoiceFromScratch and the invoice successfully created in the Target folder but i have an issue with the prefix of CommonExtensionComponents namespace xmlns:cec="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2 , is it possible to have it "ext" like xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2 as it is important for me to do validation and integration with existing systems

Please help.

Thank you

SimpleLSResourceResolver does not work for "fat jars" generated by Spring Boot

I use the ph-ubl library, version 3.3.1.

the sBaseURI sent to doStandardResourceResolving is:

jar:file:/C:/Users/tore99/IdeaProjects/pia/pia-webapp/build/libs/pia.jar!/BOOT-INF/lib/ph-ubl21-3.3.0.jar!/schemas/ubl21/maindoc/UBL-Invoice-2.1.xsd

Note that there are two instances of "!" here - because this is a jar-in-a-jar.

The base path is then set using this:

final int i = sBaseURI.indexOf ('!');

... resulting in:

BOOT-INF/lib/ph-ubl21-3.3.0.jar!/schemas/ubl21/common/UBL-CommonBasicComponents-2.1.xsd

Whereas it should be:

/schemas/ubl21/common/UBL-CommonBasicComponents-2.1.xsd

I think replacing .indexOf() with .lastIndexOf() would do the trick.

Fill InvoiceType Object from List<Map<String,String>>

Dear Sir,
How could we fill InvoiceType Object dynamically from List<Map<String,String>> or resultset or something like that, which comes from database contains all invoice date including invoice lines
Note: the column names in database are same as element names in InvoiceType

UBL 2.0 NameSpace question

Hello,
I have a question about adding name spaces.

My sample XML (which I need to make) has these name spaces:

_xmlns:qdt:urn:oasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2
_xmlns:ccts:urn:oasis:names:specification:ubl:schema:xsd:CoreComponentParameters-2 
_xmlns:stat:urn:oasis:names:specification:ubl:schema:xsd:DocumentStatusCode-1.0
_xmlns:cbc:urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2
_xmlns:cac:urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2
_xmlns:udt:urn:un:unece:uncefact:data:draft:UnqualifiedDataTypesSchemaModule:2
_xmlns:urn:oasis:names:specification:ubl:schema:xsd:Invoice-2

My generated invoice XML has these name spaces:

_xmlns:ns4:urn:oasis:names:specification:ubl:schema:xsd:Invoice-2
_xmlns:cac:urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2
_xmlns:cec:urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2
_xmlns:cbc:urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2
__prefix:ns4

This is the code I tried to add for example qdt, but it's not added:

MapBasedNamespaceContext aNsCtx = UBL20NamespaceContext.getInstance().getClone();
aNsCtx.addMapping("qdt", "urn:oasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2");
aWriter.setNamespaceContext(aNsCtx);
final ESuccess eSuccess = aWriter.write(aInvoice, new File(fn));

Any idea what I'm doing wrong?
Thanks!

question about extension content

Hi Phillip

I have a question in ubl element ExtensionContent when I put in any (.setAny()) a custom element (Colombia) for instance "DianExtensionsType" the result xml is interrupted and not written . is there any consideration to have?

if I create a Dom document and add the node with setAny() as is in scratch example, it works well, but in the case i use an XmlType it doesn't.

Wrong IssueDate format value

Using version 6.50 of ph-ubl21, when I write to string the UBL21Invoice the IssueDate field apears like this:
cbc:IssueDate2021-03-24Z</cbc:IssueDate>

If I use version 6.4.3 of ph-ubl21 it apears like this:
cbc:IssueDate2021-03-24</cbc:IssueDate>
witch is the correct format against the CIUS-PT validator.

Creating Empty UBL Extensions

I need to create something like,

 <ext:UBLExtensions>
    <ext:UBLExtension>
       <ext:ExtensionContent>
       </ext:ExtensionContent>
    </ext:UBLExtension>
 </ext:UBLExtensions>

with UBL2.1. However, I am not able to create such a declaration. The library always gives an error saying that ext:ExtensionContet is incomplete. But I need this exact declaration. How do I do that?

EmbeddedDocumentBinaryObjectType value only Bytes() can't be String

//input
String VTL_Base64="ATjZhdik2LPYs9ipINi52KjYr9in2YTZhNmHINit2LPZhiDYp9mE2YbYp9i12LEg2YTZhNiw2YfYqAIOMzAwMTg4ODY1MDAwMDMDEzIwMjItMDQtMDhUMjM6MzI6MTYEBzEwOTcuMDAFBjE0My4wOQ==";
//--------------------------------
DocumentReferenceType drt3 = new DocumentReferenceType();
drt3.setID ("QR");
AttachmentType atype3= new AttachmentType();
EmbeddedDocumentBinaryObjectType Emdb3 = new EmbeddedDocumentBinaryObjectType();
Emdb3.setMimeCode("text/plain");
Emdb3.setValue(VTL_Base64.getBytes());
//output is Something else not like input. Is there a solution to this problem?

Warning Message

Hello,

I'm starting to test your library and I got a warning message with the method readXMLDOM, the XML is loaded, but the message is:

WARN com.helger.commons.xml.sax.ReadableResourceSAXInputSource - Failed to open input stream for [cpPath=C:/temp/Invoice.xml; urlResolved=true; URL=null]

Maybe is not an important message, but I prefer ask you.

Best Regards,

Pablo Alvarez

The simple code is:

    final Document xmlDoc = DOMReader.readXMLDOM (new ClassPathResource (strFilename),
                                                  new DOMReaderSettings ().setSchema (EUBL20DocumentType.INVOICE.getSchema ()));

    final InvoiceType xmlUBLObject = UBL20Reader.readInvoice (xmlDoc);

    String s = xmlUBLObject.getAccountingSupplierParty().getCustomerAssignedAccountIDValue();

Error when run createinvoicefromscratch

I'm using these libraries in my project:

  • junit-4.13.2.jar
  • ph-commons-10.1.0.jar
  • ph-ubl21-6.2.1.jar
  • ph-xsds-xmldsig-2.6.0.jar

when i run the CreateInvoiceFromScratchFuncTest.testCreateInvoiceFromScratch , i faced the following error . either with java 8 or java 11 . the error is as following :

Exception in thread "main" java.lang.NoClassDefFoundError: com/helger/xsds/ccts/cct/schemamodule/IdentifierType
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at oasis.names.specification.ubl.schema.xsd.invoice_21.InvoiceType.setID(InvoiceType.java:4269)
at javaapplication13.JavaApplication13.testCreateInvoiceFromScratch(JavaApplication13.java:56)
at javaapplication13.JavaApplication13.main(JavaApplication13.java:41)
Caused by: java.lang.ClassNotFoundException: com.helger.xsds.ccts.cct.schemamodule.IdentifierType
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 27 more

XmlAdapter

Hello, great work,

I wonder if we can define custom XmlAdapter annotations for types.
Thank you.

[ph-ubl20] The value of 'DocType' may not be null!

I am trying to use UBL20WriterBuilder with a customized definition based on UBL like this way:

UBL20WriterBuilder<CustomDocumentType> ubl20Builder = new UBL20WriterBuilder<>(CustomDocumentType.class);

When trying to instantiate I get the following stacktrace:

java.lang.NullPointerException: The value of 'DocType' may not be null!
	at com.helger.commons.ValueEnforcer.notNull(ValueEnforcer.java:219)
	at com.helger.commons.ValueEnforcer.notNull(ValueEnforcer.java:199)
	at com.helger.jaxb.builder.AbstractJAXBBuilder.<init>(AbstractJAXBBuilder.java:49)
	at com.helger.jaxb.builder.AbstractWritingJAXBBuilder.<init>(AbstractWritingJAXBBuilder.java:71)
	at com.helger.jaxb.builder.JAXBWriterBuilder.<init>(JAXBWriterBuilder.java:65)
	at com.helger.ubl20.UBL20WriterBuilder.<init>(UBL20WriterBuilder.java:37)
	at com.helger.ubl20.UBL20WriterBuilder.<init>(UBL20WriterBuilder.java:48)
	at com.example.MainApplication.buildCustomDocument(MainApplication.java:224)

Is there no option here? I suppose it is failing due there is not similar document supported.

Support for json

Are there any plans for json support? Or will it be xml only for now. Just wondering since I really like the library but it would be useful to have support for json aswell.

Unable to use in OSGi container

Hello!

Can the library be used in OSGi containers? (like Apache Felix or Apache Karaf)
I noticed the libraries are bundled so I tried using the read/write/marshal utils in a project that runs on Karaf.
The following exception was thrown when the JAXB Context was created:

javax.xml.bind.JAXBException: Provider com.sun.xml.internal.bind.v2.ContextFactory could not be instantiated: javax.xml.bind.JAXBException: "oasis.names.specification.ubl.schema.xsd.applicationresponse_21" doesnt contain ObjectFactory.class or jaxb.index

What may cause this is described here

Thanks!

Determine Type of document from XML String

I am trying to parse XML string to UBL document/object.
Here's the code:
InvoiceType ublInvoice = UBL21Reader.invoice().read(xmlString);
This works when I know the type of document so I can easily read with UBL21Reader.
In case if I do not have the type then how can I parse XML string to UBL document object?
Is there any way of generic UBL document or any way to extract document/invoice type code from XML?
Is there any provider in UBL21Reader or other class through which I can determine the type of document from an XML string?
So based on that type I can read through UBL21Reader.

Support for ublpe21

The current version of ublpe is using UBL 2.0 but it would be great to include support for UBL 2.1

Adding the Genericode documents to the classes

Would it be possible to add the "Genericode" namespace for CodeList to the project as well? While the file format is quite trivial, having the values available could be quite nice. This question might be a bit ambiguous, ideally I would start with parsing the Genericode documents. But I think it would certainly make sense to automatically generate for example all possible QuantityTypes, or something like QuantityTypeUnitCodeEnumeration.

Two questions about UBLExtensionType

Hi Philip,
Thank you for your great library.
If have to use a specific extension in this place :

<cec:UBLExtensions>
        <cec:UBLExtension>
            <cec:ExtensionContent>
                 <aife:FactureExtension>        <!-- this one -->
                       <aife:CategoryCode>...
  1. So, if I understand the code, I must derive the CodeType class as made in HazardousCategoryCodeType and renamed it ?

  2. How, can I add the nameSpace "xmlns:aife="urn:AIFE:Facture:Extension" in the output of the UBL21Writer ?

custom XSD schema

first of all i would like to thank you to make developers life easy , i have custom XSD , it is based on UBL2.1 and i would like to use this library to generate sources and start creating invoices based on it , i don't how to start , i cloned this repo and i replaced the XSD with our XSD , the sources generated successfully , i referenced the JAR file in in a new project but it seems i am doing something wrong , i have attached my custom UBL2.1 for your reference , i tried many plugins to generate the sources with no luck
would you please direct me how to start , thanks .

UBL2.1.zip

Question: namespaces prefixes

Hello Phax

I find Intereseting this libraries for UBL. I am making a test to use it in Colombia. I saw yo in a thread you solved a case appearing ns4 prefix in root. I am doing this:

aBuilder.setNamespaceContext(UBL22NamespaceContext.getInstance() );

and result xml is

<ns4:Invoice xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns4="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xsi:schemaLocation="http://www.dian.gov.co/contratos/facturaelectronica/v1 ../../../schemas/XSD/r1/DIAN_UBL.xsd

no matter what I put in UBL22NamespaceContext

bu I am not able to see or to understand how can be changed the "ns4" prefix.

what i need is something like this

<fe:Invoice xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns4="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"

ph-ubl-jaxb-plugin example

Hi!!! Is there any example about hot to use ph-ubl-jaxb-plugin? please could you let me know if is there any example using ph-ubl-jaxb-plugin? i need to add custom methods to Ubl specification...

Use Java 8 date time classes

Use the following global bindings:

<xjc:javaType name="java.time.LocalDateTime" xmlType="xs:dateTime" adapter="..." />
<xjc:javaType name="java.time.LocalTime" xmlType="xs:time" adapter="..." />
<xjc:javaType name="java.time.LocalDate" xmlType="xs:date" adapter="..." />
<xjc:javaType name="java.time.Duration" xmlType="xs:duration" adapter="..." />

No Prefix is geting added after adding the namespace context

final MapBasedNamespaceContext aNSContext = UBL21NamespaceContext.getInstance ().getClone ();
    aNSContext.clear();
    aNSContext.addDefaultNamespaceURI ("urn:oasis:names:specification:ubl:schema:xsd:Invoice-2");
    aNSContext.addMapping ("cac", CUBL21.XML_SCHEMA_CAC_NAMESPACE_URL);
    aNSContext.addMapping ("cbc", CUBL21.XML_SCHEMA_CBC_NAMESPACE_URL);
    aNSContext.addMapping ("cec", CUBL21.XML_SCHEMA_CEC_NAMESPACE_URL);
    aNSContext.addMapping ("ds", CXMLDSig.NAMESPACE_URI);

   // typeUBL21WriterBuilder.setMarshallerCustomizer( GenericJAXBMarshaller )
    typeUBL21WriterBuilder.setNamespaceContext( aNSContext );

By default its adding NS in XML

<ns4:Invoice xmlns:ns4="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:ns3="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:ns2="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">
ns2:UBLExtensions
ns2:UBLExtension
<ns2:ExtensionContent />
</ns2:UBLExtension>
</ns2:UBLExtensions>
Dummy Invoice number
2022-11-16Z
<ns3:AccountingSupplierParty />
<ns3:AccountingCustomerParty />
ns3:TaxTotal
10
ns3:TaxSubtotal
10
10
ns3:TaxCategory
Z
10
ns3:TaxScheme
VAT
</ns3:TaxScheme>
</ns3:TaxCategory>
</ns3:TaxSubtotal>
</ns3:TaxTotal>
ns3:LegalMonetaryTotal
10
</ns3:LegalMonetaryTotal>
ns3:InvoiceLine
1
10
<ns3:Item />
</ns3:InvoiceLine>
</ns4:Invoice>

Dependencies:

implementation group: 'com.helger.ubl', name: 'ph-ubl21', version: '6.7.0'
// https://mvnrepository.com/artifact/com.helger.ubl/ph-ubl21-codelists
implementation group: 'com.helger.ubl', name: 'ph-ubl21-codelists', version: '6.7.0'

Implementation of JAXB-API has not been found on module path or classpath.

I try to use UBL2.1 version.
in test method I got the error when try to create invoice from scratch.

public static void main(String[] args) {
		String sCurrency = "EUR";

		// Create domain object
		InvoiceType aInvoice = new InvoiceType ();
	
		// Fill it
		aInvoice.setID ("Dummy Invoice number");
		aInvoice.setIssueDate (PDTFactory.getCurrentXMLOffsetDateUTC ());
	
		SupplierPartyType aSupplier = new SupplierPartyType ();
		aInvoice.setAccountingSupplierParty (aSupplier);
	
		CustomerPartyType aCustomer = new CustomerPartyType ();
		aInvoice.setAccountingCustomerParty (aCustomer);
	
		MonetaryTotalType aMT = new MonetaryTotalType ();
		aMT.setPayableAmount (BigDecimal.TEN).setCurrencyID (sCurrency);
		aInvoice.setLegalMonetaryTotal (aMT);
	
		InvoiceLineType aLine = new InvoiceLineType ();
		aLine.setID ("1");
	
		ItemType aItem = new ItemType ();
		aLine.setItem (aItem);
	
		aLine.setLineExtensionAmount (BigDecimal.TEN).setCurrencyID (sCurrency);
	
		aInvoice.addInvoiceLine (aLine);
	
		// Add some TaxTotal
		/**
		 * <pre>
		<cac:TaxSubtotal>
		  <cbc:TaxableAmount currencyID="EUR">10.00</cbc:TaxableAmount>
		  <cbc:TaxAmount currencyID="EUR">10.00</cbc:TaxAmount>
		  <cac:TaxCategory>
			<cbc:ID schemeID="UNCL5305" schemeAgencyID="6">Z</cbc:ID>
			<cbc:Percent>10.00</cbc:Percent>
			<cac:TaxScheme>
			  <cbc:ID schemeAgencyID="6" schemeID="UN/ECE 5153">VAT</cbc:ID>
			</cac:TaxScheme>
		  </cac:TaxCategory>
		</cac:TaxSubtotal>
		 * </pre>
		 */
		{
		  final TaxSubtotalType aTaxSubtotal = new TaxSubtotalType ();
		  aTaxSubtotal.setTaxableAmount (BigDecimal.TEN).setCurrencyID (sCurrency);
		  aTaxSubtotal.setTaxAmount (BigDecimal.TEN).setCurrencyID (sCurrency);
	
		  final TaxCategoryType aTaxCategory = new TaxCategoryType ();
		  final IDType aTCID = new IDType ();
		  aTCID.setSchemeID ("UNCL5305");
		  aTCID.setSchemeAgencyID ("6");
		  aTCID.setValue ("Z");
		  aTaxCategory.setID (aTCID);
	
		  aTaxCategory.setPercent (BigDecimal.TEN);
	
		  final TaxSchemeType aTaxScheme = new TaxSchemeType ();
		  final IDType aTSID = new IDType ();
		  aTSID.setSchemeID ("UNCL5305");
		  aTSID.setSchemeAgencyID ("6");
		  aTSID.setValue ("VAT");
		  aTaxScheme.setID (aTSID);
		  aTaxCategory.setTaxScheme (aTaxScheme);
	
		  aTaxSubtotal.setTaxCategory (aTaxCategory);
	
		  final TaxTotalType aTaxTotal = new TaxTotalType ();
		  aTaxTotal.setTaxAmount (BigDecimal.TEN).setCurrencyID (sCurrency);
		  aTaxTotal.addTaxSubtotal (aTaxSubtotal);
		  aInvoice.addTaxTotal (aTaxTotal);
		}
	
		// Write to disk
		UBL21Writer.invoice().write(aInvoice, new File ("target/dummy-invoice.xml"));
	}

pom.xml

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>com.helger.ubl</groupId>
      <artifactId>ph-ubl-parent-pom</artifactId>
      <version>6.6.3</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>
  

  <dependencies>

    <!-- https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-impl -->
    <dependency>
      <groupId>com.sun.xml.bind</groupId>
      <artifactId>jaxb-impl</artifactId>
      <version>3.0.0</version>
    </dependency>


    <dependency>
      <groupId>com.helger.ubl</groupId>
      <artifactId>ph-ubl21-codelists</artifactId>
      <version>6.6.3</version>
    </dependency>
    <dependency>
      <groupId>com.helger.ubl</groupId>
      <artifactId>ph-ubl21</artifactId>
      <version>6.6.3</version>
    </dependency>

  </dependencies>

Error:

Exception in thread "main" java.lang.IllegalArgumentException: Failed to create JAXB context for package 'oasis.names.specification.ubl.schema.xsd.invoice_21' using ClassLoader jdk.internal.loader.ClassLoaders$AppClassLoader@4459eb14
        at com.helger.jaxb.JAXBContextCacheKey._createFromPackageAndClassLoader(JAXBContextCacheKey.java:165)
        at com.helger.jaxb.JAXBContextCacheKey.createJAXBContext(JAXBContextCacheKey.java:202)
        at com.helger.jaxb.JAXBContextCache.lambda$new$0(JAXBContextCache.java:81)
        at com.helger.commons.cache.MappedCache.getFromCache(MappedCache.java:337)
        at com.helger.jaxb.JAXBContextCache.getFromCache(JAXBContextCache.java:124)
        at com.helger.jaxb.JAXBContextCache.getFromCache(JAXBContextCache.java:166)
        at com.helger.jaxb.builder.AbstractJAXBBuilder.getJAXBContext(AbstractJAXBBuilder.java:164)
        at com.helger.jaxb.builder.AbstractWritingJAXBBuilder.createMarshaller(AbstractWritingJAXBBuilder.java:80)
        at com.helger.jaxb.builder.JAXBWriterBuilder.createMarshaller(JAXBWriterBuilder.java:232)
        at com.helger.jaxb.builder.JAXBWriterBuilder.write(JAXBWriterBuilder.java:298)
        at com.helger.jaxb.IJAXBWriter.write(IJAXBWriter.java:381)
        at com.helger.jaxb.IJAXBWriter.write(IJAXBWriter.java:234)
        at com.helger.jaxb.IJAXBWriter.write(IJAXBWriter.java:195)
        at Test.main(Test.java:98)
Caused by: javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.
 - with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory]
        at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:131)
        at javax.xml.bind.ContextFinder.find(ContextFinder.java:318)
        at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:478)
        at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:435)
        at com.helger.jaxb.JAXBContextCacheKey._createFromPackageAndClassLoader(JAXBContextCacheKey.java:155)
        ... 13 more
Caused by: java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
        at javax.xml.bind.ServiceLoaderUtil.nullSafeLoadClass(ServiceLoaderUtil.java:92)
        at javax.xml.bind.ServiceLoaderUtil.safeLoadClass(ServiceLoaderUtil.java:125)
        at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:128)
        ... 17 more

Open PEPPOL support

Is there any support for generating / reading Open PEPPOL formats of documents?

UBL invoice namespacing

Hi Philip,

First of all, thanks for your great library.

I want to use it to create an invoice and then marshal it to XML with UBL21Writer.writeInvoice. That works, but I have a problem with the namespacing in the resulting XML. It looks something like

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<ns4:Invoice
    xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
    xmlns:ns2="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"
    xmlns:ns3="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
    xmlns:ns4="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">
    <UBLVersionID>2.1</UBLVersionID>
    <CustomizationID>urn:www.cenbii.eu:transaction:biitrns010:ver2.0:extended:urn:www.peppol.eu:bis:peppol4a:ver2.0:extended:urn:www.simplerinvoicing.org:si:si-ubl:ver1.1.x</CustomizationID>
...
</ns4:Invoice>

The following reproduces this (without creating a full valid invoice, but it illustrates the problem in less lines):

InvoiceType testInvoice = new InvoiceType();
IResourceErrorGroup aErrors = UBL21Validator.validateInvoice(testInvoice);
if (aErrors != null) {
    System.out.println("Errors: " + aErrors.toString());
    System.exit(1);
} else {
    System.out.println("No errors");
}

Obviously, there are errors and I get

The content of element 'ns4:Invoice' is not complete.

How do I get the correct namespaces, what am I doing wrong?

Thanks!

Question: Namespaces in DianExtension

Hi Phillip,

I'm using ph-ubl21 and ph-ubl-dian @6.5.0 to generate an invoice like the one in CreateInvoiceFromScratchFuncTest.java

To add the DianExtension I followed the advice from #30 (comment) like:

       ....

        // https://github.com/phax/ph-ubl/issues/30 -> convert to DOM element Dian UBL Extension
        final JAXBContext jc = JAXBContext.newInstance(DianExtensionsType.class);

        // Creating the Document object to wrap DianExtension element
        final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        final Document dianDocument = dbf.newDocumentBuilder().newDocument();
        final Marshaller marshaller = jc.createMarshaller();

        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        marshaller.marshal(new JAXBElement<>(new QName("dian:gov:co:facturaelectronica:Structures-2-1", "DianExtensions", "sts"), DianExtensionsType.class, dianExtension), dianDocument);

        final UBLExtensionsType ublExtensions = new UBLExtensionsType();
        final UBLExtensionType ublExtension = new UBLExtensionType();
        final ExtensionContentType extensionContent = new ExtensionContentType();

        extensionContent.setAny(dianDocument.getDocumentElement());
 
       ...

        final UBL21WriterBuilder<InvoiceType> aBuilder = UBL21Writer.invoice();
        final MapBasedNamespaceContext aNsCtx = UBL21NamespaceContext.getInstance().getClone();
        aNsCtx.addDefaultNamespaceURI("urn:oasis:names:specification:ubl:schema:xsd:Invoice-2");
        aNsCtx.removeMapping("cec");
        aNsCtx.addMapping("ext", "urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2");
        aBuilder.setNamespaceContext(aNsCtx);

        // Write to disk (We can use a DianUBLWriter that checks the content)
        final ESuccess eSuccess = aBuilder.write(aInvoice, new File("somefilepath.xml"));

This generates:

<?xml version="1.0" encoding="UTF-8"?>
<Invoice xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
         xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"
         xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
         xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">
    <ext:UBLExtensions>
        <ext:UBLExtension>
            <ext:ExtensionContent>
                <DianExtensions xmlns:ns3="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
                                xmlns:ns2="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
                                xmlns="dian:gov:co:facturaelectronica:Structures-2-1">
                    <InvoiceControl>
                        <InvoiceAuthorization>18760000001</InvoiceAuthorization>
                        <AuthorizationPeriod>
                            <ns2:StartDate>2019-01-19Z</ns2:StartDate>
                            <ns2:EndDate>2030-01-19Z</ns2:EndDate>
                        </AuthorizationPeriod>
                        ...
                        ...

My question is:

  • Is it ok to generate a new Namespace (ns2 & ns3) in the DianExtension even if the namespace is already defined in the root (cbc & cac) ? Do you know how can I modify/fix this?

  • I understand that defining the defaultNamespace in DianExtension will not have any difference from defining it from the root, is that right ?

Thanks a lot for your time and work with this library, it has helped me a lot.

ph-ubl generating JAXB Classes

Can you let me know an example of how to generate JAXB Classes from xsd files. I need to do this with my own set of modified xsd files.
Thanks in advance

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.