fxt - The Functional XML Transformation Tool

Functional Document Model (FDM)

-----------------

The signature of the structure including the FDM code gives an overview of the provided features. The names are mostly self-explaining, however a description of the FDM features is given bellow the signature.

signature FDM =
  sig
    type Attribute
    datatype Tree =
      ELEM of int * Attribute vector * Forest
    | TEXT of UniChar.Vector
    | PI of UniChar.Vector * Forest
    withtype Forest = Tree vector

    val emptyTree : Tree
    val emptyForest : Forest

    val hasElementType : Unicode.Vector -> Tree -> bool
    val text : Unicode.Vector -> Tree
    val element : Unicode.Vector -> Attribute vector -> Tree vector -> Tree
    val processingInstruction : Unicode.Vector -> Unicode.Vector -> Tree
    val isElement : Tree -> bool
    val isText : Tree -> bool
    val isProcessingInstruction : Tree -> bool
    val getElementType : Tree -> Unicode.Vector
    val getElement : Tree -> (Unicode.Vector * Attribute vector * Tree vector)
    val getText : Tree -> Unicode.Vector
    val hasTextContent : Tree -> bool
    val getTextContent : Tree -> Unicode.Vector
    val getProcessingInstruction : Tree -> (Unicode.Vector*Unicode.Vector)
    val hasAttribute : Unicode.Vector -> Tree -> bool
    val getAttribute : Unicode.Vector -> Tree -> Unicode.Vector
    val Tree2UnicodeVector : Tree -> Unicode.Vector
    val sons : Tree -> Forest

    val getAttributes : Tree -> Attribute vector
    val getAttributeValue : Attribute -> Unicode.Vector
    val getAttributeName : Attribute -> Unicode.Vector
    val makeAttribute : Unicode.Vector -> Unicode.Vector -> Attribute
    val replaceAttribute : Attribute vector -> Unicode.Vector -> Unicode.Vector -> Attribute vector
    val addAttribute : Attribute vector -> Unicode.Vector -> Unicode.Vector -> Attribute vector
    val addAttributes : Attribute vector -> Attribute vector -> Attribute vector
    val deleteAttribute : Attribute vector -> Unicode.Vector -> Attribute vector
    val changeAttribute : Tree -> Unicode.Vector -> Unicode.Vector -> Tree
    val insertAttribute : Tree -> Unicode.Vector -> Unicode.Vector -> Tree
    val removeAttribute : Tree -> Unicode.Vector -> Tree

    val fromList : Tree list -> Forest
    val toList : Forest -> Tree list
    val length : Forest -> int
    val lengthPred : (Tree -> bool) -> Forest -> int
    val sub : Forest * int -> Tree
    val extract : Forest * int * int option -> Forest
    val concat : Forest list -> Forest
    val app : (Tree -> unit) -> Forest -> unit
    val map : (Tree -> 'a) -> Forest -> 'a vector
    val foldl : (Tree * 'a -> 'a) -> 'a -> Forest -> 'a
    val foldr : (Tree * 'a -> 'a) -> 'a -> Forest -> 'a
    val appi : (int * Tree -> unit) -> Forest * int * int option -> unit
    val mapi : (int * Tree -> 'a) -> Forest * int * int option -> 'a vector
    val foldli : (int * Tree * 'a -> 'a) -> 'a -> Forest * int * int option -> 'a
    val foldri : (int * Tree * 'a -> 'a) -> 'a -> Forest * int * int option -> 'a
    val deleteAll : (Tree -> bool) -> Forest -> Forest
    val deleteFirst : (Tree -> bool) -> Forest -> bool * Forest
    val deleteFirstN : int -> (Tree -> bool) -> Forest -> int * Forest
    val deleteLast : (Tree -> bool) -> Forest -> bool * Forest
    val deleteLastN : int -> (Tree -> bool) -> Forest -> int * Forest
    val deleteIth : int -> Forest -> Forest
    val filter : (Tree -> bool) -> Forest -> Forest
    val filterFirst : (Tree -> bool) -> Forest -> Tree

    val countTreeNodes : Tree -> int
    val countForestNodes : Forest -> int

     
    val sort : (Tree*Tree -> bool) -> Forest -> Forest
    (*  use (>=,<=) functions to preserve the order 
        of elements with equal keys  *)
      
    val concatForests : Forest vector -> Forest

    val putTree : Tree -> string -> string option -> unit
    val putForest : Forest -> string -> string option -> unit
    val printTree : Tree -> unit
    val printForest : Forest -> unit
  end

where:

Tree
the abstract representation for an XML document or for some part of an XML document
Forest
A sequence of XML trees (as for example the sons of an element node)
Attribute
the type of the attributes of XML elements
emptyTree
emptyForest
values provided as representation of the empty XML tree and forest respectively.
hasElementType
returns true if the element supplied as the first argument is a node element and has the name supplied as the second argument. If applied on a non node element or if the node element on which it is applied has not this type (name) false is returned.
text
creates a text node with the specified content.
element
creates an element node with the name, attributes and the sons vector given as arguments.
processingInstruction
creates a processing instruction node for a processor given as the first argument and the content given as the second.
isElement
isText
isProcessingInstruction
returns true if the node given as argument is an element, text or processing instruction respectively.
getElementType
returns the type of the element node given as argument. If the node is not an element an exception is thrown.
getElement
returns for an element node a triplet formed of its type, the attributes and the vector of sons. If the node is not an element an exception is thrown.
getText
returns for a text node the content of the node. If the node is not a text an exception is thrown
hasTextContent
returns true for a text node or for an element node which only contains a text node
getTextContent
if applied on a text node returns its content. If applied on an element node which only contains a text node returns the content of this text node. Otherwise an exception is thrown.
getProcessingInstruction
returns for a processing instruction node a pair containing the corresponding processor and instruction. If the node is not a processing instruction an exception is thrown.
hasAttribute
applied on an element node given as its second argument returns true if the element has an attribute with the name given as the first argument. If the node argument is not an element an exception is thrown.
getAttribute
returns for an element node given as the second argument having the attribute given as the first argument the value of this argument. If the node is not an element or if it has not a such attribute an exception is thrown.
Tree2UniCodeVector
gives the Unicode string representation for a tree
sons
given a tree, returns the forest of itssons
getAttributes
returns for an element node a vector containing its attributes. If the node is not an element an exception is thrown.
getAttributeValue
returns the value of the attribute given as argument.
getAttributeName
returns the name of the attribute given as argument.
makeAttribute
creates an attribute with the name given as the first argument and the value given by the second.
replaceAttribute
returns a vector obtained by replacing in the vector of attributes given as the first argument the attribute with the name and the value given by the second and the third attribute. If there is no attribute with the given name the vector is returned unchanged as the result.
addAttribute
returns a list obtained by adding to the vector of attributes given as the first argument the attribute with the name and the value given by the second and the third attribute. If the vector has the attribute with the given name already the value of this attribute is set to the given value in the returned vector.
addAttributes
returns a list obtained by adding to the list of attributes given as the first argument the list of the attributes given as the second argument. If in both lists, attributes of the second list will overwrite those in the first in the returned list.
deleteAttribute
returns a vector obtained from the vector of attributes given as the first arguments by deleting the attribute with the name given as the second argument. If no attribute with the given name is present in the input vector the vector is returned unchanged as the result.
changeAttribute
returns for an element node the element node obtained by replacing in its attributes list the value of the attribute given as the first argument with the value given as the third argument. If no attribute with the given name is present in the attribute list of the input element node, it is added to the attributes list of the output node. If the input node is not an element an exception is thrown.
insertAttribute
returns for an element node the element node obtained by inserting in its attributes list an attribute with the name given as the second argument and the value given as the third. If the attribute with the given name is already present in the attribute list of the input element node, it is changed to the new value in the output node. If the input node is not an element an exception is thrown.
removeAttribute
returns for an element node the element node obtained by removing from its attribute list the element with the name given as the second argument. If no attribute with the given name is present in the attribute list of the input node, the input node is returned unchanged as the result.
fromList,length, sub, extract, concat, app, map, foldl, foldr, appi, mapi, foldli, foldri
have the SML signification, given that the type Forest is represented as a vector of Trees.
toList
transforms a forest in a list of trees
lengthPred
given a predicate working on trees and a forest, returns the number of trees in the forest that satisfy the predicate.
deleteAll
given a predicate working on trees and a forest, returns a forest obtained from the input forest by eliminating all the trees that satisfy the predicate.
deleteFirst
given a predicate working on trees and a forest, returns a pair formed of a boolean and a forest. The boolean indicates if the predicate was fulfilled by any of the trees in the forest. The output forest is obtained from the input forest by eliminating the first tree that satisfy the predicate.
deleteFirstN
given an integer number, a predicate working on trees and a forest returns a pair formed of an integer and a forest. The output forest is obtained from the input forest by eliminating the first trees that satisfy the predicate, in a number that is not greater than the indicated number. The integer value returned indicates how many trees in the input forest were actually deleted (may be less than the requested number).
deleteLast
given a predicate working on trees and a forest, returns a pair formed of a boolean and a forest. The boolean indicates if the predicate was fulfilled by any of the trees in the forest. The output forest is obtained from the input forest by eliminating the last tree in the forest that satisfy the predicate.
deleteLastN
given an integer number, a predicate working on trees and a forest, returns a pair formed of an integer and a forest. The output forest is obtained from the input forest by eliminating the last trees that satisfy the predicate, in a number which is not greater than the indicated number. The integer value returned indicates how many trees in the input forest were actually deleted (may be less than the requested number).
deleteIth
returns a forest obtained by deleting the i-th tree (i given as the first argument) in the forest given as the second argument.
filter
given a predicate over trees and a forest returns the trees in the forest that satisfy the predicate.
filterFirst
given a predicate over trees and a forest returns the first tree in the forest that satisfies the predicate.
countTreeNodes
counts the nodes in a tree.
countForestNodes
counts the nodes in a forest.
sort
given an order relationship as a predicate working on a pair of trees and a forest, returns a forest where trees are sorted such that the predicate order is fulfilled.
concatForest
concatenates a vector of Forest-s
putTree
given a tree, a file name and an encoding option, writes the tree to the specified file in the specified encoding. If the encoding specified is NONE, UTF8 is used.
putForest
given a forest, a file name and an encoding option, writes the forest to the specified file in the specified encoding. If the encoding specified is NONE, UTF8 is used.
printTree
given a tree prints it at the standard output.
printForest
given a forest prints it at the standard output.

-----------------

A. Berlea (aberlea@psi.uni-trier.de)