GithubHelp home page GithubHelp logo

phax / ph-ubl Goto Github PK

View Code? Open in Web Editor NEW
105.0 16.0 40.0 1.07 GB

Java library for reading and writing UBL 2.0, 2.1, 2.2, 2.3 and 2.4 documents

License: Apache License 2.0

CSS 0.97% Java 99.03%
ubl-tr ubl java eprocurement einvoicing edelivery invoice ph-ubl phoss

ph-ubl's Issues

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="..." />

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.

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!

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.

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,

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.

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"

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 ?

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

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

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.

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

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.

XmlAdapter

Hello, great work,

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

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

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 ?

[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.

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?

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

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

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.

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

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.

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!

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.

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

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 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?

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

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'

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

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...

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.

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.

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?

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!

Open PEPPOL support

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

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;

....

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

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 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.

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.

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?

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.