XLIFF (0.1.1)


Base Format

Partially fueled by an argument about EBML, I came up with this.
It has little to do with LIFF, but, hell, I am not really using LIFF (it ended up too close to RIFF and too generally ugly...).
This format shows itself to be kind of a pain to code up, but this is not entirely unexpected.

Cleaning up spec some from 10-29 version, minor alterations.
Stripping out container stuff, as it clutters the spec and doesn't really make sense in this context anyways (keeping the old version as the idea may be adaptable to a different format).

Goals

A binary format with similar flexibility to XML (X);
Support for large files and datasets (L);
Sort of like RIFF and IFF (IFF).

This will be a TLV format with attributes and namespaces similar to XML.
It will use a tag dictionary to help reduce the total file size.
It should be acceptable for random access and "big chunks of data" style uses (like RIFF, IFF, and EBML).

Basic Coding

Numbers

The MSB (bit 7) serves to indicate the precense of following (higher order) bytes.

0xxxxxxx, -64..63
1xxxxxxx 0xxxxxxx, -8192..8191
1xxxxxxx 1xxxxxxx 0xxxxxxx, -1M..1M
...

Values are in Low-High order and with 2s complement encoding.
As a result, the sign is implicitly contained in bit 6 of the last byte.

The maximum value of a number depends on the implementation, and an implementation is allowed to refuse overly large numbers.
However, I will spec that the limit should be at least 32 bits (a 35 bit number with the upper 4 bits either all 0 or 1).

Strings

String
{
Number len; //length if >0, dictionary index if <0, empty string if 0
if(len>0)byte str[len];
}

Strings may be indexed in a dictionary. The exact semantics for dictionaries will depend on context.

Nodes

Node:
{
String ns;
String tag;
Number alen;
if(alen>0)byte attr[alen];
Number dlen;
if(dlen>0)byte data[dlen]; //the contents depend on the ns and tag
}

Attr:
{
String ns;
String tag;
Number dlen;
if(dlen>0)byte data[dlen];
}

In tags and attributes, negative chunk lengths are reserved.

Implicit XLIFF attributes are allowed in nodes without restrictions as they are not generally viewed as part of the content.
Duplicate attributes are not allowed.
Attributes may not contain either tags or other attributes (other non-nestable structures will generally be allowed). Attributes should be kept small in both size and number.


Dictionaries

Tag Dictionary

There will be a dictionary responsible for namespaces, tags, and attribute names:
This dictionary will behave similarly to a stack;
Any new strings are added to the end of the current dictionary level (encoded directly and not allready present);
On descent into a node, the dictionary is retained from the parent, creating a new level;
Any new strings are added to the end of the current dictionary level;
On exit from a node, any strings added in that level are removed (making it as if the descent had not occured).

The use of a dictionary allows denser packing (due to, eg, tags being 1 or 2 bytes).
Fairly dense packing might require building the entire dictionary upfront, but an encoder can have less dense packing, eg, by just encoding strings directly.
The need for upfront dictionaries for packing to work well is related to ideas for allowing faster processing by not having to descend into subnodes to build an up-to-date dictionary, and also to allow random access in some cases.

Body Dictionaries

Each namespace will also have a "body dictionary", which may be used for compressing content strings in a content specific manner. The maintainence of these dictionaries is largely left to the format in question (however, they will implicitly pop off anything added within a node).

The format is a tree, with the default toplevel tag flagging the format.

Special tags could exist for maintenence purposes (eg: adding a basic set of common strings to the dictionary, ...).
Like XML, some special tags may exist prior to the root to define things (the base dictionary, ...).


Namespaces

The empty string namespace is the "default" namespace.

Except builtin XLIFF namespaces (default, XLIFF, ...) namespaces are to be declared prior to use.
Formats are given control over how namespaces are used/defined.

Namespaces refer to several URI's:
the Type URI, which defines the physical type of the container (eg: XML).
the Namespace URI, which defines the semantic type of the container (eg: an XML Namespace).

Any namespaces beginning with "XLIFF" are reserved for use by XLIFF.
Further:
XLIFF.*: basic XLIFF namespaces, failure to understand tags/attributes should cause failure;
XLIFF.S.*: semantic XLIFF namespaces, these are allowed to be ignored, but should be preserved;
XLIFF.O.*: optional XLIFF namespaces, these may be ignored or stripped off without effecting content.

There will be a basic "XLIFF" namespace, and being unable to parse tags in this namespace will be viewed as an error (this namespace will handle things which may change the format of subsequent data, effect dictionaries, ...). XLIFF attributes are required to be understood before attempting to parse the contents of a node.

"XLIFF.S" will be used for semantic XLIFF tags, failure to understand them will not compromise decoding of the format.

"XLIFF.O" will be used for optional XLIFF tags, failure to understand or removal of them will not compromise decoding of the format.

"XLIFF.NS" could be a namespace for namespace declatations (like in XML). eg, "XLIFF.NS:foo" as an attribute could declare a foo namespace.
the content of these tags could be an array of pairs of strings, eg:
"TypeURI", "xliff:foo_container", "NSURI", "xliff:bar_ns".


Base Tags/Attributes


XLIFF:Header
An tag required at the start of an XLIFF file serving to mark it as a valid XLIFF file, and to give general info about the file.

XLIFF:TypeName Header Attribute, gives a general "file type name" used for identifying the type (appart from examining the contents or namespaces). It is encoded as a raw string.

XLIFF:HeaderFlags Header Attribute
Contains a number marking various flags for a file. Unknown flags may be ignored.
1&=dictionary is static within the file.

Other attributes may be found in the header besides those related to XLIFF. An example would be custom or format specific tags.


XLIFF:DictStrings Tag
Defines a glob of strings to be added to the tag dictionary.
This may be used for reducing the number of occurances of some common tag which may only occure in sublevels or such.

XLIFF:NodeFlags Attribute
Contains a number marking various flags for a node. Unknown flags may be ignored.
1&=this node is compound;
2&=dictionary is static within this node.

XLIFF.O:JUNK Tag/Attribute
Marks a space as being "junk", thus allowing leaving some space for new tags, attributes, or padding.



XML in XLIFF


There are 2 ways to do XML in XLIFF:
    A unified document (all the content, or at least the toplevel, is XML);
    A mixed document (the toplevel is not necissarily XML).

In the unified document case the toplevel tag is 'XML' (with at least the default namespace declared as being XML), which may contain any xml header tags and the xml root.
Namespace declarations are to be converted to XLIFF style.

In the mixed document case, at least the basic xml namespaces are to be declared in the file toplevel (along probably with others).
The nstype for XML is 'xliff:binxml'.

String Globs

All textual data will be represented by a number of strings stuck end to end.
These will use a "textglob dictionary", which will follow the same rules as that for the tag dictionary.

Attribute data is defined as a glob of strings.

An empty tag value flags a glob of textual data. The body for this is a string glob.