XMLDBX Handbook

  • warning: include(/tmp/fortune.txt): failed to open stream: No such file or directory in /home/mohawksoft/org/www/htdocs/includes/common.inc(1696) : eval()'d code on line 1.
  • warning: include(): Failed opening '/tmp/fortune.txt' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /home/mohawksoft/org/www/htdocs/includes/common.inc(1696) : eval()'d code on line 1.


Basic XML Data Exchange


XMLDBX is nothing more than an XML data exchange format. While XML is a very powerful and flexible data format, it only declares structure, not specifics about the nature of data. One thousand applications saving data in XML may have one thousand different type definitions. SOAP, which set out to address this problem, is a format and exchange specification for XML, but it suffers the “design by committee” problems of requiring too much and thus becoming less efficient and more cumbersome.

XMLDBX is not a generic format like SOAP. It has a very specific purpose, to convey programmatic data suitable for various programming environments and databases. As such, it has a fairly limited range of data types. By using the XMLDBX types and tags, it is possible to create XML data streams that “automagically” create objects in different programming environments. For instance, XMLDBX has been used to interface perl and C/C++ with PHP based web sites. The XMLDBX PHP extension can accept an XML stream and return a fully initialized PHP class.


string xmldbx_serialize(varname, object)

Supported: PHP

The xmldbx_serialize API accepts a language specific object, a single variable or class, and creates an XMLDBX formatted string that represents the object. Depending on the programming language used, either the object or the language itself must support enumeration and discovery of arbitrary data.

object xmldbx_deserialize(string)

Supported: PHP

The xmldbx_deserialize API accepts a string previously created with xmldbx_serialize or a correctly formatted XMLDBX string that represents a class of data. The string is parsed with the expat library is is reconstituted into the native class.

variable xmldbx(varspec, string)

Supported: PostgreSQL

The xmldbx API is used to extract a single variable from an XMLDBX formatted string. The string is parsed using the expat library until the variable referenced by “varspec” is found and returned. The “varspec” string is formatted using the period character “.” to separate XML tags. By convention, XMLDBX always starts with a top level data tag called “data.” The string “data.class.subclass.var” will reference: <xmldbx><data><class><subclass><var>1</var></subclass></class></data></xmldbx>

variable xmldbx(varspec, string, index)

Supported: PostgreSQL

Operates exactly as xmldbx(varspec,string) except stores the result in an indexed array. When used in a database, allows for forward referencing by index. Once the variable is found in a query, it can be referenced by the xmldbx(index) API without having to re-parse the XML string. The index is an arbitrary number between 0 and 31.

variable xmldbx_attr(varspec, string, attr)

Supported: PostgreSQL

Operates exactly as xmldbx(varspec,string) except that it returns the specified attribute. A list of attributes are documented in the “XMLDBX Types” document.

variable xmldbx_attr(varspec, string, attr, index)

Supported: PostgreSQL

Operates exactly as xmldbx_attr(varspec,string, attr) except that it also stores its result in the indexed result array.

variable xmldbx(index)

Supported: PostgreSQL

Works in conjunction with xmldbx(varspec,string,index) and xmldbx_attr(varspec, string, attr, index) in that it returns a previously parsed data or attribute item.

string readfile(filename)

Supported: PostgreSQL

Used as a utility for loading data, opens the file referenced by “filename” and returns it as a platform appropriate string.

XMLDBX Type and Tag Specification


A variable is a single item of data. It may be a core type or it may be an aggregate type comprised of multiple core types or even other aggregate types.


Variable names must adhere to the XML standards for variable naming, non conforming names will be replaced with 'xag' and be given a name attribute which will conform to HTML standards.


Variable values can be stored either as an attribute within an XML tag or as the explicit value between begin and end tags. A compliant XMLDBX decoder should work with either format.


Variables can have “attributes” assigned to them. This allows extra information to be passed from the XML creation program to the XML decoding program. The following attributes can be found in the XMLDBX format.


The type attribute “Classname” indicates to the decoder the type of object to re-create, its form is “cn='CLASSNAME' “where “CLASSNAME” represents a type known to the decoder.


The type attribute “Extra” indicated to the decoder some aspect of the data represented by the tag that both the encoder and decoder agree, its form is “ex='attr'” where “attr” is known to both encoder and decoder.

IS Reference

The type attribute “Is Reference” indicates to the decoder that variable represented by the tag is a reference, its form is “I='1'.” This is used by PHP and optional.


The type attribute “Length” indicated the length of the variable to the decoder, its form is “cb='len'” where “len” represents the length of the object.


The type attribute “Name” indicates the name of the tag when it includes characters which are invalid for an XML name, its form is “n='name'” where “name “ represents the name of the tag.

Reference Count

The type attribute “Reference Count” indicates to the decoder the number of times the tags is referenced by other variables, its form is “C='n'” where 'n' is a number. This is used by PHP and is optional.


The type attribute “Reference” indicates that the XML tag's data will be referenced by later tags, its form is “R='XXXXXXX'” where “XXXXXX” is a hexadecimal reference number that is used by the reference type to address this tag.


The type attribute indicates the type of data represented by the tag, its form is “t='TYPE'” where “TYPE” is representative of the variable type.


The value attribute “v='value'” is used to compact the XML stream and save space. Its use is shown below.


The version tag indicates the version of the XML format. Version is currently “1.0.”

Core Types

Core types are non-aggregate types, that is they contain only one value. A core type should also be natively represented in the various platformed, integer numbers, floating point or numeric numbers, strings, booleans, or individual characters.


A boolean is a simple TRUE or FALSE evaluation. In C and C++ it is not defined. In SQL it is define as “boolean.” (This varies by SQL vendor.)

<varname t='b'>true</varname>

<varname t='b' v='true'/>


A floating point number is a number with decimal point information, such as “3.1415.” In C and C++ this is represented using “float” or “double.” In SQL this is represented as “numeric.” (This varies by SQL vendor.)

<varname t='f'>number</varname>

<varname t='f' v='number'/>


An long is an integer number with no decimal point. In C and C++ this is an “int.” In SQL this is an “integer.”

<varname t='l'>number</varname>

<varname t='l' v='number'/>


A string is a series of alpha-numeric characters. In C or C++ this is represented as a character pointer, “char *” In SQL, this can be represented as a “varchar.”

<varame t='sz'>string data</varname>

<varname t='sz' v='string data'/>

Aggregate Types

Aggregate types are collections of multiple data objects. An aggregate type has no individual value, other than those of its component objects.


Arrays are an aggregate of a singular component type.

<varname t='a'>

more varaibles



Objects are aggregates of different types.

<varname t='o'>

more variables



A reference references a previous value. The value of a reference is the same as the “reference attribute” of a previous tag.

<varname t='r' v='6B3224'/>