Skip to content

Syntea/xdef

Repository files navigation

X-definition

About

X-definition is a technology designed to describe the validation, processing and construction of data in XML format (as well as JSON, YAML and similar).

X-definition is a technology designed by Syntea software group a.s. for professional description, validation, processing and creation of the structure of XML, JSON, YAML, INI and CSV documents. It allows the user not only to define the structure of XML documents, but also to specifically describe their processing and construction. X-definition also allows you to define and use code in external user methods.

Homepage: http://www.xdef.org

This project is implemented for the platform Java 1.8+ (additional note: up to the version 41.0.4 for the platform Java 1.6+).

License

This project is Open Source Software (OSS) licensed under Apache 2.0 license.

Illustrative examples

You can try the following examples online at: http://xdef.syntea.cz/tutorial/examples/validate.html.

Example 1: Essential concepts

Let´s have the following XML data:
<Employee
  FirstName = "Andrew"
  LastName  = "Aardvark"
  EnterDate = "1996-03-12"
  Salary    = "21700"
>
  <Address
    Street = "Broadway"
    Number = "255"
    Town   = "Beverly Hills"
    State  = "CA"
    Zip    = "90210"
  />
  <Competence>electrician</Competence>
  <Competence>carpenter</Competence>
</Employee>






This is complete X-definition describing the XML data on the left:
<xd:def
  xmlns:xd = "http://www.xdef.org/xdef/4.2"
  xd:root  = "Employee"
>
  <Employee
    FirstName = "required string()"
    LastName  = "required string()"
    EnterDate = "required date()"
    Salary    = "optional decimal()"
  >
    <Address
      Street = "required string()"
      Number = "required int()"
      Town   = "required string()"
      State  = "required string()"
      Zip    = "required int()"
    />
    <Competence xd:script = "occurs 1..5">
      required string()
    </Competence>
  </Employee>
</xd:def>

You can try it on the "Playground-online".

Example 2: References

XML data:
<Family>
  <Father
    GivenName  = "John"
    FamilyName = "Smith"
    PersonalID = "7107130345"
    Salary     = "18800"
  />
  <Mother
    GivenName  = "Jane"
    FamilyName = "Smith"
    PersonalID = "7653220029"
    Salary     = "19400"
  />
  <Son
    GivenName  = "John"
    FamilyName = "Smith"
    PersonalID = "9211090121"
  />
  <Daughter
    GivenName  = "Jane"
    FamilyName = "Smith"
    PersonalID = "9655270067"
  />
  <Residence
    Street     = "Small"
    Number     = "5"
    Town       = "Big"
    Zip        = "12300"
  />
</Family>
X-definition describing the XML data:
<xd:def
  xmlns:xd = "http://www.xdef.org/xdef/4.2"
  xd:root  = "Family"
>
  <Family>
    <Father    xd:script = "occurs 0..1; ref Person"  />
    <Mother    xd:script = "occurs 1..1; ref Person"  />
    <Son       xd:script = "occurs 0..*; ref Person"  />
    <Daughter  xd:script = "occurs 0..*; ref Person " />
    <Residence xd:script = "occurs 1;    ref Address" />
  </Family>
  
  <Person
    GivenName  = "string()" 
    FamilyName = "string()" 
    PersonalID = "long()"
    Salary     = "optional int()"
  />
  <Address
    Street = "string()"
    Number = "int()"
    Town   = "string()"
    Zip    = "int()"
  />
</xd:def>





You can try it on the "Playground-online".

Annotation

X‑definition is designed for description and processing of data in the XML format and also JSON, YAML and similar.

X-definition is an open-source tool that describes the structure and properties of data values in an XML document. In addition, X-definition allows you to describe the processing and construction of XML objects. X-definition can thus replace existing technologies commonly used for XML validation — namely Data Type Definition (DTD), XML Schema (XSD), Schematron, and XML Stylesheet Language Transformations (XSLT).

X-definition allows you to combine XML document validation with data processing (by describing the actions assigned to each event when processing XML objects). Compared to technologies based on DTD and XML schema, the advantage of X-definition is (not only) higher readability and easier maintenance. X-definition was designed to handle XML data sets of virtually unlimited size beyond the size of working memory.

An important feature of X-definition is the maximum respect for the structure of the described data. The form of an X-definition is an XML document with a structure similar to the XML data being described. This allows a quick and intuitive description of the XML data and its processing.

The properties of XML items (and the events that can occur during the process) are described by the X-script language. In most cases, it is sufficient to replace the values described in the XML data model with the X-script language in the X-definition. You can also incrementally add the required data processing actions to the X-script. X-definition technology also allows you to generate source code for classes representing XML elements described by an X-definition in Java. Such a class is called an X-component. Instances of XML data can be used in the form of X components (similar to JAXB technology).

Starting with X-definition version 4.2, it is possible to validate and process data in JSON and YAML, Properties, Windows INI, and CSV (comma-separated values) formats in addition to XML. JSON data structure models are described by xd:json or xd:ini elements.

The X-definition also allows language localization of the tag names of the described XML data. Different language versions can be described by elements in the xd:lexicon object.

Documentation and online playground

For the complete documentation see the directory xdef/src/documentation.

You can try your X-definition examples and experiments at the following "Playground-online":

Media

Articles, lectures, presentations, videos:

Usage in other projects

Check and download available versions

Links:

Version package content

File assets in a version package:

  • xdef-{version}.jar - the java-library X-definition
  • xdef-{version}-userdoc.zip - complete user documentation and tutorial examples
  • xdef-{version}-javadoc.jar - html-documentation of java source code generated from the java source code
  • xdef-{version}-sources.jar - origin java source code
  • xdef-{version}-src.zip - java source code insertable directly into your source code, very similar to xdef-{version}-sources.jar
  • xdef-{version}.pom - maven metadata of the package

Usage in your maven project

Configure your file pom.xml:

  • add the following dependency on a release version in the Central Maven Repository:

    <dependencies>
        …
        <dependency>
            <groupId>org.xdef</groupId>
            <artifactId>xdef</artifactId>
            <version>[release version]</version>
        </dependency>
    <dependencies>
  • or add the following dependency on a snapshot (or also release) version in the Central Maven Snapshot Repository (it's necessary to add the following repository):

    <dependencies>
        …
        <dependency>
            <groupId>org.xdef</groupId>
            <artifactId>xdef</artifactId>
            <version>[snapshot (or also release) version]</version>
        </dependency>
    </dependencies>
    …
    <repositories>
        …
        <repository>
            <id>central-snapshot</id>
            <url>https://central.sonatype.com/repository/maven-snapshots</url>
            <releases><enabled>false</enabled></releases>
            <snapshots><enabled>true</enabled></snapshots>
        </repository>
    </repositories>

Building this project

Source code at GitHub:

Prerequisities:

Frequent building operations:

  • cleaning before any compiling, building, deploying, etc.:

    mvn clean
  • compile all java-resources, respectively all compilable resources:

    mvn compile
  • build the snapshot package:

    mvn package
  • build the snapshot package including documentation, javadoc, sources:

    mvn package -Pdoc
  • using the profile "skipTests", avoid junit-tests:

    mvn package -PskipTests
  • using the profile "testOnAllJvms", junit-tests will be run on all configured Java platforms, i.e.:

    • Java-8 (by default it is run in the module "xdef")
    • Java-11 (it is run in the module "xdef-test11")
    • Java-17 (it is run in the module "xdef-test17")
    • Java-21 (it is run in the module "xdef-test21")
    • Java-25 (it is run in the module "xdef-test25")
    mvn package -PtestOnAllJvms
  • build the release package:

    mvn package -Prelease
  • build the release package including documentation, javadoc, sources:

    mvn package -Prelease,doc

Deploying to the maven central repository

Prerequisities:

Deploying:

  • build and deploy the X-definition snapshot package to the central maven snapshot repository (immediate deploy without processes validation and publishing):

    mvn deploy -Pdoc,dm-central
  • build and deploy the X-definition release package to the central maven repository

    mvn deploy -Prelease,doc,dm-central,sign