HXQ-0.18.2: A Compiler from XQuery to Haskell

Text.XML.HXQ.XQuery

Contents

Description

HXQ is a fast and space-efficient compiler from XQuery (the standard query language for XML) to embedded Haskell code. The translation is based on Haskell templates. It also provides an interpreter for evaluating ad-hoc XQueries read from input or from files and optional database connectivity using HDBC. For more information, look at http://lambda.uta.edu/HXQ/.

Synopsis

The XML Data Representation

type Prefix = StringSource

Namespace prefix

type URI = StringSource

Namespace URI

type LocalName = StringSource

Local name

data QName Source

A qualified name has a namespace prefix, a URI, and a local name

Constructors

QName 

Fields

prefix :: Prefix
 
uri :: URI
 
localName :: LocalName
 

Instances

type Attributes = [(QName, String)]Source

XML attributes are bindings from qualified names to values

data XTree Source

A rose tree representation of XML data. An XML element is: XElem tagname atributes preorder parent children. The preorder numbering is the document order of elements. The parent is a cyclic reference to the parent element.

Constructors

XElem !QName !Attributes !Int XTree [XTree]

an XML tree node (element)

XAttr !QName !String

attribute construction

XText !String

an XML tree leaf (PCDATA)

XInt !Int

an XML tree leaf (int)

XFloat !Double

an XML tree leaf (double)

XBool !Bool

an XML tree leaf (boolean)

XPI String String

processing instruction

XGERef String

general entity reference

XComment String

comment

XError String

error message

XNull

null value

XType Type

type information

XNoPad

marker for no padding in XSeq

Instances

type XSeq = [XTree]Source

A sequence of XML fragments

type TVar = IntSource

A type variable

type TQualifier = CharSource

Type qualifier: *, +, or ?

data Type Source

An XQuery type

Constructors

TVariable TVar

type variable (needed for polymorphic type inference)

TBase QName

xs:integer, xs:string, ...

TItem String

item(), node(), ...

TNamed QName

reference to a user-defined type

TElement String Type

element tag { t }

TAttribute String Type

attribute name { t }

TAny

any element or attribute content

TEmpty

()

TSequence Type Type

t1, t2

TInterleaving Type Type

t1 & t2

TChoice Type Type

t1 | t2

TQualified Type TQualifier

t*, t+, or t?

Instances

putXSeq :: XSeq -> IO ()Source

Print the XQuery result (which is a sequence of XML fragments) without buffering.

The XQuery Compiler

xq :: String -> Q ExpSource

Compile an XQuery that may perform IO (such as reading an XML document or calling a user function). When the compiled code is evaluated, it returns a value of type IO XSeq.

xe :: String -> Q ExpSource

Compile an XQuery expression that does not perform IO. When the compiled code is evaluated, it returns a value of type XSeq.

qx :: QuasiQuoterSource

Quasi-quotation for HXQ (for ghc 6.09 or later). For example, [qx| doc("data/cs.xml")//gpa |] is equivalent to xq "doc(\"data/cs.xml\")//gpa".

The XQuery Interpreter

xquery :: String -> IO XSeqSource

Evaluate the XQuery using the interpreter.

eval :: XSeq -> IO XSeqSource

The XQuery interpreter as an XQuery function.

Validation using XML Schema

validateFile :: FilePath -> FilePath -> IO BoolSource

Validate the XML document against the XML Schema. Also done using the validate XQuery form.

The XQuery Compiler with Database Connectivity

xqdb :: String -> Q ExpSource

Compile an XQuery that may perform IO and/or queries a database. When the compiled code is evaluated, it returns Connection -> IO XSeq.

The XQuery Interpreter with Database Connectivity

xqueryDB :: String -> Connection -> IO XSeqSource

Evaluate the XQuery with database connectivity using the interpreter.

Shredding and Publishing XML Documents Using a Relational Database

type Path = [String]Source

XPath to reach a table/column

data Table Source

A relational schema representation

Constructors

Table String Path Bool [Table]

table-name relative-path mixed-content? components

Column String Path Int

column-name relative-path max-byte-size

Instances

genSchemaSource

Arguments

:: Connection

database connection

-> FilePath

XML document pathname

-> String

schema name

-> [String]

excluded tags

-> IO Table 

Create a schema for an XML document into the database under the given name. The excluded tags are HTML tags to be ignored

shredSource

Arguments

:: Connection

database connection

-> FilePath

XML document pathname

-> String

schema name

-> IO () 

Store an XML document into the database under the given name.

shredCSource

Arguments

:: String

database name

-> FilePath

XML document pathname

-> String

schema name

-> Q Exp 

Store an XML document into the database under the given name. Generates Haskell code. It's 3 times faster than shred.

isSchemaSource

Arguments

:: Connection

database connection

-> String

schema name

-> IO Bool 

True if there is a relational schema stored in the database under the given name

printSchemaSource

Arguments

:: Connection

database connection

-> String

schema name

-> IO () 

Print the relational schema stored in the database under the given name

createIndexSource

Arguments

:: Connection

database connection

-> String

schema name

-> String

the tag name of the elements to be indexed

-> IO () 

Create a secondary index on tagname for the shredded document under the given name..

Other Database Functions

connectSource

Arguments

:: String

database name

-> IO Connection 

Connect to a relational database

disconnectSource

Arguments

:: Connection

database connection

-> IO () 

Disconnect from the relational database

commitSource

Arguments

:: Connection

database connection

-> IO () 

commit the updates to the database

rollbackSource

Arguments

:: Connection

database connection

-> IO () 

rollback the updates from the database