Did you know ... Search Documentation:
Packs (add-ons) for SWI-Prolog

Package "xsd"

Title:XML Schema validation with Prolog
Rating:Not rated. Create the first rating!
Latest version:0.1.6
SHA1 sum:bb8dedb347c0564ccf2ff009bb3df0f6ef981485
Author:Falco Nogatz <fnogatz@gmail.com>
Jona Kalkus <jonakalkus@gmail.com>
Maintainer:Falco Nogatz <fnogatz@gmail.com>
Jona Kalkus <jonakalkus@gmail.com>
Packager:Falco Nogatz <fnogatz@gmail.com>
Home page:https://github.com/jonakalkus/xsd
Download URL:https://github.com/jonakalkus/xsd/releases/*.zip


No reviews. Create the first review!.

Details by download location


XML Validator in SWI-Prolog

Validate an XML Document against an XML Schema in SWI-Prolog.


All you need is SWI-Prolog. See there for installation instructions.

Only for development purposes the library(tap) is needed.


It is possible to create a pre-compiled file which increases the tool's performance significantly. The command line interface is compiled using swipl's -c option:

swipl -g main -o cli.exe -c cli.pl

The `.exe` suffix is chosen for compatibility with Windows systems.

Usage as CLI

A command line interface is provided, too. You can directly execute it via

swipl -g main cli.pl -- schema.xsd instance.xml

Call with `--help` instead of the filenames to get more options.

After the pre-compilation step mentioned before, the created executable can be called via:

./cli.exe schema.xsd instance.xml

Usage with SWI-Prolog

The library(xsd) exports the following predicates:

  • xsd_validate(+Schema, +Document)
    Validates an XML Document with Identifier `Document` against an XML Schema `Schema`.

    The library(xsd/flatten) exports the following predicates:

  • `xml_flatten(+Input, ?Identifier)`
    Loads an XML file from source `Input` into the prolog database.
    An `Identifier` can be freely chosen, otherwise it will be generated.
  • remove_file(+Identifier)
    Deletes all nodes corresponding to `Identifier` from the prolog database.

Example Call

?- use_module(library(xsd)),
   xsd_validate('path/to/schema.xsd', 'path/to/instance.xml').

XML File Representation

Once an XML file is loaded using xml_flatten/2, it will be represented by the following predicates:

  • node(File_ID, ID, Namespace, Node)
    Each node in the document `File_ID` is represented by a node/4 fact with the unique identifier `ID`. Also, the namespace and the name of the element are stated.
  • node_attribute(File_ID, ID, Attribute, Value)
    For every attribute a `node_attribute/4` fact is generated. It stores the `Attribute` and `Value` of an attribute associated to node `ID` inside document `File_ID`.
  • text_node(File_ID, ID, Node)
    Text inside the document `File_ID` is represented as `text_node/3` facts. These have unique identifiers like regular document nodes and store the text `Node`.

Supported Features

Please see FEATURES.md for full list of currently supported components of the XML Schema Definition Language.


Developed and tested in SWI-Prolog, version 7.4.1, 64 bit.

Contents of pack "xsd"

Pack contains 139 files holding a total of 109K bytes.