HXQ-0.17.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 Name = StringSource

Element tagname or attribute name

type AttList = [(Name, String)]Source

Attribute list

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 !Name !AttList !Int XTree [XTree]

an XML tree node (element)

XAttr !Name !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 Name String

processing instruction

XGERef String

general entity reference

XComment String

comment

XError String

error report

XNull

null value

XType Ast

type information

XNoPad

marker for no padding in XSeq

Instances

type XSeq = [XTree]Source

A sequence of XML fragments

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.

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

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 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