📜 ⬆️ ⬇️

Documenting information exchange formats is easy and simple.

1. Introduction


Back in 2001, the W3C consortium developed recommendations for the XML Schema Definition Language (XSD), combining the most popular schema definition languages ​​into one standard. The main goal that was pursued at the same time was to obtain a platform-independent standard that all participants in the information exchange can use. By curbing chaos, XML has become the most attractive format for information exchange. Nowadays, the XML format in information technology is used very widely, going far beyond the simple exchange of data.

As a result of the popularity and breadth of using XML, both the increase in the volume and the complexity of the structure of the data transmitted in XML become. A more young and simple JSON format, which “selected” all information flows from XML with a more or less simple structure of message formats, made its own contribution to this process. Today we have the fact that XSD schemas that describe the data structure of XML messages have become large and complex. It became very difficult to read large and complex schemes in text form, so there is a need for both special software and up-to-date documentation that describes XML message formats.
In this article I will talk about how the problem of documenting XML message formats used for information exchange was solved ...



2. Issues


The best XSD schema documentation is the XSD schema itself. This axiom is valid until the scheme exceeds a certain threshold of complexity or you do not meet a person who does not know or does not want to read the XSD scheme. When developing an application that uses XSD schemes, you may also be faced with the requirement to describe the developed message formats in the technical or accompanying documentation.
')
If you are involved in developing applications with loosely coupled or distributed components in a service-oriented architecture, you are familiar with the concepts of SOA (service-oriented architecture) and SOAP (Simple Object Access Protocol), then very soon there will be a moment when you yourself need to be updated. documentation more than your customer.

Therefore, the question “Do you need documentation?” Has an unambiguous answer “Yes”; sooner or later everyone who is involved in developing software using XML will face this.

The next obvious question is what should be the result of documenting formats? It is quite difficult to answer this question, because different users of the result (architects, developers, analysts, technical writers, administrators, representatives of the Customer and all the others) have completely different tasks.

Solve this problem in different ways. Someone (for example, the developers of oXygen) followed the path of a full description of the XSD scheme. As a result, the description becomes even more difficult to understand than the scheme itself. Others stand on the fact that everyone should be able to read XSD schemes and no documentation is needed - sometimes only because they understand that they are not able to keep this documentation up to date. As always, the truth lies somewhere in the middle ...

3. The essence of the problem


The process of developing message formats can be represented by the following major steps (see figure below).



Iteration number 1:


The process of developing message formats is iterative. After the first iteration has been completed and the comments have been received, the next one starts immediately from step No. 2:


The discovered "bottleneck" makes a very difficult choice between quality and development time. It is almost impossible to choose between them because both options are needed at once!

4. Documenting Message Formats


The most obvious way to document formats is with pens. You open the circuit and describe its element by element, which takes a lot of working time. If the scheme is large or there are many of them, then within a few days you will acquire a specific red tint to the eyes of a professional programmer and a persistent aversion to this work. Next comes the understanding that it cannot be that such work has not been automated for a long time and the subsequent persistent search for a finished tool.

Before looking for an automation tool, it would be nice to understand how you would like to use it and what should be the result of its work?

All the work on documenting message formats fits into the following usage scenarios:


As for the result, over many years of working with diagrams and their documentation, I developed my own understanding of what the result of describing message formats should be, what is called “from the plow”. The basis of the concept can be described in just three points:


What does the format description look like in a document? In the process of work, the table with the description of the formats of the elements of the XSD scheme changed more than once, both in the set of columns and in their content, until it received the columns described in the following:


An example of the format description is given below in the “Solution” section ...

5. Search for a solution


Based on the use scenarios and the desired result, the main requirements for the functions of the tool were formed, which should automate this activity:


Despite the prevalence of using XSD and a large number of software that works with it, I still could not find a tool that at least partially met these requirements.

However, the problem was more relevant than ever and such a tool was created ...

6. Decision


For those who are interested in looking at the tool, I will provide links to it in the commentary after the article, in the framework of the same article it is more interesting to look at the result as an example of documenting message formats.

6.1. An example of processing a documented scheme


Here is the result of the description of the element formats obtained from the XSD schema with the filled "documentation".

6.1.1. Source diagram


Spoiler header
<?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/Customer" xmlns:tns="http://www.example.org/Customer" elementFormDefault="qualified"> <xsd:annotation> <xsd:documentation>     .</xsd:documentation> </xsd:annotation> <xsd:element name="Customer"> <xsd:annotation> <xsd:documentation>.</xsd:documentation> </xsd:annotation> <xsd:complexType> <xsd:sequence> <xsd:element name="CustomerId" type="xsd:int"> <xsd:annotation> <xsd:documentation>ID .</xsd:documentation> </xsd:annotation> </xsd:element> <xsd:element name="FirstName" type="xsd:string"> <xsd:annotation> <xsd:documentation>.</xsd:documentation> </xsd:annotation> </xsd:element> <xsd:element name="LastName" type="xsd:string"> <xsd:annotation> <xsd:documentation>.</xsd:documentation> </xsd:annotation> </xsd:element> <xsd:element name="Address"> <xsd:annotation> <xsd:documentation>.</xsd:documentation> </xsd:annotation> <xsd:complexType> <xsd:sequence> <xsd:element name="StreetAddress" type="xsd:string"> <xsd:annotation> <xsd:documentation> .</xsd:documentation> </xsd:annotation> </xsd:element> <xsd:element name="City" type="xsd:string"> <xsd:annotation> <xsd:documentation> .</xsd:documentation> </xsd:annotation> </xsd:element> <xsd:element name="Zip" type="xsd:string"> <xsd:annotation> <xsd:documentation> . >>>       .</xsd:documentation> </xsd:annotation> </xsd:element> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema> 


6.1.2. The result




6.2. An example of using an external description


Here is the result of the description of the element formats obtained from the XSD schema with an empty “documentation”.

6.2.1. Source diagram


Spoiler header
 <?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/Customer" xmlns:tns="http://www.example.org/Customer" elementFormDefault="qualified"> <xsd:element name="Customer"> <xsd:complexType> <xsd:sequence> <xsd:element name="CustomerId" type="xsd:int" /> <xsd:element name="FirstName" type="xsd:string" /> <xsd:element name="LastName" type="xsd:string" /> <xsd:element name="Address"> <xsd:complexType> <xsd:sequence> <xsd:element name="StreetAddress" type="xsd:string"/> <xsd:element name="City" type="xsd:string"/> <xsd:element name="Zip" type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema> 


6.2.2. External description file data


Spoiler header
 \matr      . Customer . CustomerId ID . FirstName . LastName . Address . StreetAddress  . City  . Zip  . >>>       . 


6.2.3. The result



Please note that the result obtained is completely identical to the result of processing the documented scheme!

6.3. An example of comparing two schemes


This is a description of the element formats obtained by comparing different versions of the XSD schema.

6.3.1. Source diagram


Spoiler header
 <?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/Customer" xmlns:tns="http://www.example.org/Customer" elementFormDefault="qualified"> <xsd:element name="Customer"> <xsd:complexType> <xsd:sequence> <xsd:element name="CustomerId" type="xsd:int" /> <xsd:element name="FirstName" type="xsd:string" /> <xsd:element name="LastName" type="xsd:string" /> <xsd:element name="Address"> <xsd:complexType> <xsd:sequence> <xsd:element name="StreetAddress" type="xsd:string"/> <xsd:element name="City" type="xsd:string"/> <xsd:element name="Zip" type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema> 


6.3.2. Previous version of the scheme


Spoiler header
 <?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/Customer" xmlns:tns="http://www.example.org/Customer" elementFormDefault="qualified"> <xsd:element name="Customer"> <xsd:complexType> <xsd:sequence> <xsd:element name="CustomerId" type="xsd:int" /> <xsd:element name="FullName" type="xsd:string" /> <xsd:element name="Address"> <xsd:complexType> <xsd:sequence> <xsd:element name="StreetAddress" type="xsd:string"/> <xsd:element name="City" type="xsd:string"/> <xsd:element name="Country" type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema> 


6.3.3. The result



The new elements “FirstName”, “LastName” and “Zip” have all columns in bold. The “Address” element has changed position - only the first column is highlighted in bold. Deleted elements “FullName” and “Country” are highlighted in gray. Also, the background of the lines helps to “read” the changes.

This view makes the differences easy to read, both on screen and in print.

7. Summary


Now, to make a new version of the album formats for several hundred XSD schemes, it takes only a few minutes. The output file in the Word document format is obtained in the amount of nearly 1500 sheets. The problems of errors in the description disappeared, and most importantly - the irrelevance of the description of the schemes. Thus, it turned out to successfully automate one of the most time-consuming areas in the management of application development.

Source: https://habr.com/ru/post/418345/


All Articles