Home  /  Blog  /  How to : UBL implementation with xsd2code++

How to : UBL implementation with xsd2code++

May 2021

Universal Business Language (UBL) is a royalty-free model of business document information in XML syntax. UBL was developed by Organization for the Advancement of Structured Information Standards (OASIS) to be as an entry point to electronic commerce for small and medium-sized business.

If you have to read or write XML documents compliant with the UBL standard, xsd2code++ can help you and save you a lot of time.

So if you want to : 

  • Use UBL 2.1 document standard
  • Reduce development time significantly
  • Do not use external or paid libraries
  • Use standardized electronic business document exchange
  • Automate your invoicing, ordering, billing and etc.
  • xsd2code++ can help you 

Step-by-step guide

We are going to see in this article how to read and write an invoice with the code generated by xsd2code. In this article we are going to use the 2.1 version of UBL with an example code which is realized under .NET5.

    Creating a new project and generating the code

    The first step is to create a console project in Visual Studio and add the UBL schemas.

      Image showing the solution explorer and where the files are

      Then, to generate the code, choose the XML schema corresponding to the document you want to produce, in this example it is the invoice. A simple right click on the schema allows you to access the code generator settings:

      Image showing how to start Xsd2Code for solution explorer

      The important options are the activation of XML attributes and the read and write method of XML serialization

      Image showing the serialization setting being enabled along with the xml attributes setting

      Avoid circular references ! UBL schemas contains circular references. To avoid a StackOverFlow exception, InitializeFields must be at "none" or "collection". The complex types will not be created which avoids the circular reference.

      Just in case you didn't know, this will generate a class with attributes based on the xml, JSon, BSon or Messagepack data file or schema, with serialization enabled you will have the serialization and deserialization functions in the class depending on which formats you've enabled.

      From there depending on what your needs are you can, through c# and the generated functions, code your program to generate the files you need in the right way following the class that has been generated from either the schema or a data file, thanks to Xsd2Code you can stick with the Xml and switch to or add other output formats like JSon.

      Code Sample

      A sample implementation is available on GitHUB. We provide a set of examples based on schemas and standards such as FpML or UBL.

      https://github.com/xsd2code/XmlSchema