STXT - Semantic Text
Built for humans. Reliable for machines.

STXT Tutorial

1. What is STXT?
2. Basic example: a book record
3. Using namespaces
4. Validation with Templates
5. Validation with Schemas
6. Final validatable document
7. Best practices

1. What is STXT?

STXT (Semantic Text) is a hierarchical and semantic textual language, designed to be Human-First:

STXT allows representing structured documents through:

The base syntax is minimal. Advanced semantics are added through:

2. Basic example: a book record

Let’s look at a simple example of an STXT document that describes a book. There is no validation yet: it is only STXT language. Also, it has no associated namespace.

Book:
	Title: Modern software architecture
	Authors:
		Author: María Pérez
		Author: Juan García
	ISBN: 978-84-123456-7-8
	Publisher: ACME Publishing
	Published: 2025-10-01
	Summary >>
		This book offers a practical view of patterns and best practices
		for designing distributed and scalable systems.
	Chapter: Introduction to architecture
		Content >>
			In this chapter we present basic concepts:
			monoliths, microservices, and design criteria.
	Chapter: Communication between services
		Content >>
			Protocols, messaging, and integration patterns are described.

Observations:

3. Using namespaces

Namespaces allow grouping nodes into categories. Also, if a namespace is defined for a node, child nodes inherit the parent’s namespace, unless one of them redefines it.

Example of a document with a namespace:

Book (com.acme.book):
	Title: Modern software architecture
	Authors:
		Author: María Pérez
		Author: Juan García
	ISBN: 978-84-123456-7-8

In this example we see the Book node that belongs to the com.acme.book namespace. In addition, we also see nodes Title, Authors, Author, and ISBN, which, being descendants of Book, also inherit the com.acme.book namespace.

Key rules:

3.1 Special namespaces with `@`

Namespaces may or may not start with @. This indicates that they are special or reserved namespaces. For example, both templates and schemas start with @.

This is only a semantic indication, but the behavior is the same.

3.2 Document validation

To be able to semantically validate a document, it must be associated with a namespace. Once it has the namespace, a schema (@stxt.schema) or template (@stxt.template) is used to validate it. Validations are extensions to the base language, which parsers may or may not implement.

To validate a document it is necessary that it belongs to a namespace.
On the other hand, a document with a namespace is not required to be validated.

4. Validation with Templates

Templates allow defining structural and type rules in a compact way. They are ideal for prototypes and living documentation.

A template is an STXT document whose namespace is @stxt.template.

4.1 Template for books

Template (@stxt.template): com.acme.book
	Description: Template for publishing book records
	Structure >>
		Book:
			Title: (1)
			Authors: (1)
				Author: (+)
			ISBN: (1)
			Publisher: (?)
			Published: (?) DATE
			Summary: (?) TEXT
			Chapter: (+)
				Content: (?) TEXT

What this template defines:

4.2 Applying the template

A validator that supports templates must:

The STXT language does not change: the template is applied over the already-parsed tree. Depending on the parser, it may validate at the same time it parses the content.

5. Validation with Schemas

Schemas provide the same information as a template, but in a more explicit and formal way.

A schema:

5.1 Schema equivalent to the template

Schema (@stxt.schema): com.acme.book
	Node: Book
		Type: GROUP
		Children:
			Child: Title
				Min: 1
				Max: 1
			Child: Authors
				Min: 1
				Max: 1
			Child: ISBN
				Min: 1
				Max: 1
			Child: Publisher
				Max: 1
			Child: Published
				Max: 1
			Child: Summary
				Max: 1
			Child: Chapters
				Max: 1

	Node: Authors
		Children:
			Child: Author
				Min: 1

	Node: Chapters
		Children:
			Child: Chapter
				Min: 1

	Node: Chapter
		Children:
			Child: Content
				Max: 1

	Node: Title
	Node: Author
	Node: ISBN
	Node: Publisher
	Node: Published
		Type: DATE
	Node: Summary
		Type: TEXT
	Node: Content
		Type: TEXT

6. Final validatable document

Complete STXT document that can be validated with the previous template or schema:

Book (@com.acme.book):
	Title: Modern software architecture
	Authors:
		Author: María Pérez
		Author: Juan García
	ISBN: 978-84-123456-7-8
	Published: 2025-10-01
	Summary: A practical introduction to the architecture of modern systems.
	Chapter: Introduction
		Content >>
			Basic concepts and objectives of the book.

This document:

7. Best practices