hxt-7.3: A collection of tools for processing XML with Haskell.ContentsIndex
Text.XML.HXT.Arrow.XmlArrow
Portabilityportable
Stabilityexperimental
MaintainerUwe Schmidt (uwe@fh-wedel.de)
Description

Version : $Id: XmlArrow.hs,v 1.34 20061102 16:43:39 hxml Exp $

Basic arrows for processing XML documents

All arrows use IO and a global state for options, errorhandling, ...

Synopsis
class (Arrow a, ArrowList a, ArrowTree a) => ArrowXml a where
isText :: a XmlTree XmlTree
isCharRef :: a XmlTree XmlTree
isEntityRef :: a XmlTree XmlTree
isCmt :: a XmlTree XmlTree
isCdata :: a XmlTree XmlTree
isPi :: a XmlTree XmlTree
isXmlPi :: a XmlTree XmlTree
isElem :: a XmlTree XmlTree
isDTD :: a XmlTree XmlTree
isAttr :: a XmlTree XmlTree
isError :: a XmlTree XmlTree
isRoot :: a XmlTree XmlTree
hasText :: (String -> Bool) -> a XmlTree XmlTree
isWhiteSpace :: a XmlTree XmlTree
hasNameWith :: (QName -> Bool) -> a XmlTree XmlTree
hasQName :: QName -> a XmlTree XmlTree
hasName :: String -> a XmlTree XmlTree
hasLocalPart :: String -> a XmlTree XmlTree
hasNamePrefix :: String -> a XmlTree XmlTree
hasNamespaceUri :: String -> a XmlTree XmlTree
hasAttr :: String -> a XmlTree XmlTree
hasQAttr :: QName -> a XmlTree XmlTree
hasAttrValue :: String -> (String -> Bool) -> a XmlTree XmlTree
hasQAttrValue :: QName -> (String -> Bool) -> a XmlTree XmlTree
mkText :: a String XmlTree
mkCharRef :: a Int XmlTree
mkEntityRef :: a String XmlTree
mkCmt :: a String XmlTree
mkCdata :: a String XmlTree
mkError :: Int -> a String XmlTree
mkElement :: QName -> a n XmlTree -> a n XmlTree -> a n XmlTree
mkAttr :: QName -> a n XmlTree -> a n XmlTree
mkPi :: QName -> a n XmlTree -> a n XmlTree
mkqelem :: QName -> [a n XmlTree] -> [a n XmlTree] -> a n XmlTree
mkelem :: String -> [a n XmlTree] -> [a n XmlTree] -> a n XmlTree
aelem :: String -> [a n XmlTree] -> a n XmlTree
selem :: String -> [a n XmlTree] -> a n XmlTree
eelem :: String -> a n XmlTree
root :: [a n XmlTree] -> [a n XmlTree] -> a n XmlTree
qattr :: QName -> a n XmlTree -> a n XmlTree
attr :: String -> a n XmlTree -> a n XmlTree
txt :: String -> a n XmlTree
charRef :: Int -> a n XmlTree
entityRef :: String -> a n XmlTree
cmt :: String -> a n XmlTree
warn :: String -> a n XmlTree
err :: String -> a n XmlTree
fatal :: String -> a n XmlTree
spi :: String -> String -> a n XmlTree
sqattr :: QName -> String -> a n XmlTree
sattr :: String -> String -> a n XmlTree
getText :: a XmlTree String
getCharRef :: a XmlTree Int
getEntityRef :: a XmlTree String
getCmt :: a XmlTree String
getCdata :: a XmlTree String
getPiName :: a XmlTree QName
getPiContent :: a XmlTree XmlTree
getElemName :: a XmlTree QName
getAttrl :: a XmlTree XmlTree
getDTDPart :: a XmlTree DTDElem
getDTDAttrl :: a XmlTree Attributes
getAttrName :: a XmlTree QName
getErrorLevel :: a XmlTree Int
getErrorMsg :: a XmlTree String
getQName :: a XmlTree QName
getName :: a XmlTree String
getUniversalName :: a XmlTree String
getUniversalUri :: a XmlTree String
getLocalPart :: a XmlTree String
getNamePrefix :: a XmlTree String
getNamespaceUri :: a XmlTree String
getAttrValue :: String -> a XmlTree String
getAttrValue0 :: String -> a XmlTree String
getQAttrValue :: QName -> a XmlTree String
getQAttrValue0 :: QName -> a XmlTree String
changeText :: (String -> String) -> a XmlTree XmlTree
changeCmt :: (String -> String) -> a XmlTree XmlTree
changeQName :: (QName -> QName) -> a XmlTree XmlTree
changeElemName :: (QName -> QName) -> a XmlTree XmlTree
changeAttrName :: (QName -> QName) -> a XmlTree XmlTree
changePiName :: (QName -> QName) -> a XmlTree XmlTree
changeAttrValue :: (String -> String) -> a XmlTree XmlTree
changeAttrl :: (XmlTrees -> XmlTrees -> XmlTrees) -> a XmlTree XmlTree -> a XmlTree XmlTree
setQName :: QName -> a XmlTree XmlTree
setElemName :: QName -> a XmlTree XmlTree
setAttrName :: QName -> a XmlTree XmlTree
setPiName :: QName -> a XmlTree XmlTree
setAttrl :: a XmlTree XmlTree -> a XmlTree XmlTree
addAttrl :: a XmlTree XmlTree -> a XmlTree XmlTree
addAttr :: String -> String -> a XmlTree XmlTree
removeAttr :: String -> a XmlTree XmlTree
removeQAttr :: QName -> a XmlTree XmlTree
processAttrl :: a XmlTree XmlTree -> a XmlTree XmlTree
processTopDownWithAttrl :: a XmlTree XmlTree -> a XmlTree XmlTree
(+=) :: a b XmlTree -> a b XmlTree -> a b XmlTree
xshow :: a n XmlTree -> a n String
class ArrowXml a => ArrowDTD a where
isDTDDoctype :: a XmlTree XmlTree
isDTDElement :: a XmlTree XmlTree
isDTDContent :: a XmlTree XmlTree
isDTDAttlist :: a XmlTree XmlTree
isDTDEntity :: a XmlTree XmlTree
isDTDPEntity :: a XmlTree XmlTree
isDTDNotation :: a XmlTree XmlTree
isDTDCondSect :: a XmlTree XmlTree
isDTDName :: a XmlTree XmlTree
isDTDPERef :: a XmlTree XmlTree
hasDTDAttr :: String -> a XmlTree XmlTree
getDTDAttrValue :: String -> a XmlTree String
setDTDAttrValue :: String -> String -> a XmlTree XmlTree
mkDTDElem :: DTDElem -> Attributes -> a n XmlTree -> a n XmlTree
mkDTDDoctype :: Attributes -> a n XmlTree -> a n XmlTree
mkDTDElement :: Attributes -> a n XmlTree
mkDTDEntity :: Attributes -> a n XmlTree
mkDTDPEntity :: Attributes -> a n XmlTree
Documentation
class (Arrow a, ArrowList a, ArrowTree a) => ArrowXml a where
Methods
isText :: a XmlTree XmlTree
test for text nodes
isCharRef :: a XmlTree XmlTree
test for char reference, used during parsing
isEntityRef :: a XmlTree XmlTree
test for entity reference, used during parsing
isCmt :: a XmlTree XmlTree
test for comment
isCdata :: a XmlTree XmlTree
test for CDATA section, used during parsing
isPi :: a XmlTree XmlTree
test for processing instruction
isXmlPi :: a XmlTree XmlTree
test for processing instruction <?xml ...>
isElem :: a XmlTree XmlTree
test for element
isDTD :: a XmlTree XmlTree
test for DTD part, used during parsing
isAttr :: a XmlTree XmlTree
test for attribute tree
isError :: a XmlTree XmlTree
test for error message
isRoot :: a XmlTree XmlTree
test for root node (element with name "/")
hasText :: (String -> Bool) -> a XmlTree XmlTree

test for text nodes with text, for which a predicate holds

example: hasText (all (`elem` " \t\n")) check for text nodes with only whitespace content

isWhiteSpace :: a XmlTree XmlTree

test for text nodes with only white space

implemented with hasTest

hasNameWith :: (QName -> Bool) -> a XmlTree XmlTree
test whether a node (element, attribute, pi) has a name with a special property
hasQName :: QName -> a XmlTree XmlTree
test whether a node (element, attribute, pi) has a specific qualified name useful only after namespace propagation
hasName :: String -> a XmlTree XmlTree
test whether a node has a specific name (prefix:localPart ore localPart), generally useful, even without namespace handling
hasLocalPart :: String -> a XmlTree XmlTree
test whether a node has a specific name as local part, useful only after namespace propagation
hasNamePrefix :: String -> a XmlTree XmlTree
test whether a node has a specific name prefix, useful only after namespace propagation
hasNamespaceUri :: String -> a XmlTree XmlTree
test whether a node has a specific namespace URI useful only after namespace propagation
hasAttr :: String -> a XmlTree XmlTree
test whether an element node has an attribute node with a specific name
hasQAttr :: QName -> a XmlTree XmlTree
test whether an element node has an attribute node with a specific qualified name
hasAttrValue :: String -> (String -> Bool) -> a XmlTree XmlTree
test whether an element node has an attribute with a specific value
hasQAttrValue :: QName -> (String -> Bool) -> a XmlTree XmlTree
test whether an element node has an attribute with a qualified name and a specific value
mkText :: a String XmlTree
text node construction arrow
mkCharRef :: a Int XmlTree
char reference construction arrow, useful for document output
mkEntityRef :: a String XmlTree
entity reference construction arrow, useful for document output
mkCmt :: a String XmlTree
comment node construction, useful for document output
mkCdata :: a String XmlTree
CDATA construction, useful for document output
mkError :: Int -> a String XmlTree
error node construction, useful only internally
mkElement :: QName -> a n XmlTree -> a n XmlTree -> a n XmlTree
element construction: | the attributes and the content of the element are computed by applying arrows to the input
mkAttr :: QName -> a n XmlTree -> a n XmlTree
attribute node construction: | the attribute value is computed by applying an arrow to the input
mkPi :: QName -> a n XmlTree -> a n XmlTree
processing instruction construction: | the content of the processing instruction is computed by applying an arrow to the input
mkqelem :: QName -> [a n XmlTree] -> [a n XmlTree] -> a n XmlTree

convenient arrow for element construction, more comfortable variant of mkElement

example for simplifying mkElement :

 mkElement qn (a1 <+> ... <+> ai) (c1 <+> ... <+> cj)

equals

 mkqelem qn [a1,...,ai] [c1,...,cj]
mkelem :: String -> [a n XmlTree] -> [a n XmlTree] -> a n XmlTree
convenient arrow for element construction with strings instead of qualified names as tagnames, see also mkElement and mkelem
aelem :: String -> [a n XmlTree] -> a n XmlTree
convenient arrow for element constrution with attributes but without content, simple variant of mkelem and mkElement
selem :: String -> [a n XmlTree] -> a n XmlTree
convenient arrow for simple element constrution without attributes, simple variant of mkelem and mkElement
eelem :: String -> a n XmlTree
convenient arrow for constrution of empty elements without attributes, simple variant of mkelem and mkElement
root :: [a n XmlTree] -> [a n XmlTree] -> a n XmlTree
construction of an element node with name "/" for document roots
qattr :: QName -> a n XmlTree -> a n XmlTree
alias for mkAttr
attr :: String -> a n XmlTree -> a n XmlTree
convenient arrow for attribute constrution, simple variant of mkAttr
txt :: String -> a n XmlTree
constant arrow for text nodes
charRef :: Int -> a n XmlTree
constant arrow for char reference nodes
entityRef :: String -> a n XmlTree
constant arrow for entity reference nodes
cmt :: String -> a n XmlTree
constant arrow for comment
warn :: String -> a n XmlTree
constant arrow for warning
err :: String -> a n XmlTree
constant arrow for errors
fatal :: String -> a n XmlTree
constant arrow for fatal errors
spi :: String -> String -> a n XmlTree
constant arrow for simple processing instructions, see mkPi
sqattr :: QName -> String -> a n XmlTree
constant arrow for attribute nodes, attribute name is a qualified name and value is a text, | see also mkAttr, qattr, attr
sattr :: String -> String -> a n XmlTree
constant arrow for attribute nodes, attribute name and value are | given by parameters, see mkAttr
getText :: a XmlTree String
select the text of a text node
getCharRef :: a XmlTree Int
select the value of a char reference
getEntityRef :: a XmlTree String
select the name of a entity reference node
getCmt :: a XmlTree String
select the comment of a comment node
getCdata :: a XmlTree String
select the content of a CDATA node
getPiName :: a XmlTree QName
select the name of a processing instruction
getPiContent :: a XmlTree XmlTree
select the content of a processing instruction
getElemName :: a XmlTree QName
select the name of an element node
getAttrl :: a XmlTree XmlTree
select the attribute list of an element node
getDTDPart :: a XmlTree DTDElem
select the DTD type of a DTD node
getDTDAttrl :: a XmlTree Attributes
select the DTD attributes of a DTD node
getAttrName :: a XmlTree QName
select the name of an attribute
getErrorLevel :: a XmlTree Int
select the error level (c_warn, c_err, c_fatal) from an error node
getErrorMsg :: a XmlTree String
select the error message from an error node
getQName :: a XmlTree QName
select the qualified name from an element, attribute or pi
getName :: a XmlTree String
select the prefix:localPart or localPart from an element, attribute or pi
getUniversalName :: a XmlTree String
select the univeral name ({namespace URI} ++ localPart)
getUniversalUri :: a XmlTree String
select the univeral name (namespace URI ++ localPart)
getLocalPart :: a XmlTree String
select the local part
getNamePrefix :: a XmlTree String
select the name prefix
getNamespaceUri :: a XmlTree String
select the namespace URI
getAttrValue :: String -> a XmlTree String
select the value of an attribute of an element node, always succeeds with empty string as default value ""
getAttrValue0 :: String -> a XmlTree String
like getAttrValue, but fails if the attribute does not exist
getQAttrValue :: QName -> a XmlTree String
like getAttrValue, but select the value of an attribute given by a qualified name, always succeeds with empty string as default value ""
getQAttrValue0 :: QName -> a XmlTree String
like getQAttrValue, but fails if attribute does not exist
changeText :: (String -> String) -> a XmlTree XmlTree
edit the string of a text node
changeCmt :: (String -> String) -> a XmlTree XmlTree
edit the comment string of a comment node
changeQName :: (QName -> QName) -> a XmlTree XmlTree
edit an element-, attribute- or pi- name
changeElemName :: (QName -> QName) -> a XmlTree XmlTree
edit an element name
changeAttrName :: (QName -> QName) -> a XmlTree XmlTree
edit an attribute name
changePiName :: (QName -> QName) -> a XmlTree XmlTree
edit a pi name
changeAttrValue :: (String -> String) -> a XmlTree XmlTree
edit an attribute value
changeAttrl :: (XmlTrees -> XmlTrees -> XmlTrees) -> a XmlTree XmlTree -> a XmlTree XmlTree
edit an attribute list of an element node
setQName :: QName -> a XmlTree XmlTree
replace an element, attribute or pi name
setElemName :: QName -> a XmlTree XmlTree
replace an element name
setAttrName :: QName -> a XmlTree XmlTree
replace an attribute name
setPiName :: QName -> a XmlTree XmlTree
replace an element name
setAttrl :: a XmlTree XmlTree -> a XmlTree XmlTree
replace an atribute list of an element node
addAttrl :: a XmlTree XmlTree -> a XmlTree XmlTree
add a list of attributes list to an element
addAttr :: String -> String -> a XmlTree XmlTree
add (or replace) an attribute
removeAttr :: String -> a XmlTree XmlTree
remove an attribute
removeQAttr :: QName -> a XmlTree XmlTree
remove an attribute with a qualified name
processAttrl :: a XmlTree XmlTree -> a XmlTree XmlTree
process the attributes of an element node with an arrow
processTopDownWithAttrl :: a XmlTree XmlTree -> a XmlTree XmlTree
process a whole tree inclusive attribute list of element nodes see also: processTopDown
(+=) :: a b XmlTree -> a b XmlTree -> a b XmlTree

convenient op for adding attributes or children to a node

usage: tf += cf

the tf arrow computes an element node, and all trees computed by cf are added to this node, if a tree is an attribute, it is inserted in the attribute list else it is appended to the content list.

attention: do not build long content list this way because += is implemented by ++

examples:

 eelem "a"
   += sattr "href" "page.html"
   += sattr "name" "here"
   += txt "look here"

is the same as

 mkelem [ sattr "href" "page.html"
        , sattr "name" "here"
        ]
        [ txt "look here" ]

and results in the XML fragment: <a href="page.html" name="here">look here</a>

advantage of the += operator is, that attributes and content can be added any time step by step. if tf computes a whole list of trees, e.g. a list of "td" or "tr" elements, the attributes or content is added to all trees. useful for adding "class" or "style" attributes to table elements.

xshow :: a n XmlTree -> a n String
apply an arrow to the input and convert the resulting XML trees into a string representation
show/hide Instances
class ArrowXml a => ArrowDTD a where

Document Type Definition arrows

These are separated, because they are not needed for document processing, only when processing the DTD, e.g. for generating access funtions for the toolbox from a DTD (se example DTDtoHaskell in the examples directory)

Methods
isDTDDoctype :: a XmlTree XmlTree
isDTDElement :: a XmlTree XmlTree
isDTDContent :: a XmlTree XmlTree
isDTDAttlist :: a XmlTree XmlTree
isDTDEntity :: a XmlTree XmlTree
isDTDPEntity :: a XmlTree XmlTree
isDTDNotation :: a XmlTree XmlTree
isDTDCondSect :: a XmlTree XmlTree
isDTDName :: a XmlTree XmlTree
isDTDPERef :: a XmlTree XmlTree
hasDTDAttr :: String -> a XmlTree XmlTree
getDTDAttrValue :: String -> a XmlTree String
setDTDAttrValue :: String -> String -> a XmlTree XmlTree
mkDTDElem :: DTDElem -> Attributes -> a n XmlTree -> a n XmlTree
mkDTDDoctype :: Attributes -> a n XmlTree -> a n XmlTree
mkDTDElement :: Attributes -> a n XmlTree
mkDTDEntity :: Attributes -> a n XmlTree
mkDTDPEntity :: Attributes -> a n XmlTree
show/hide Instances
Produced by Haddock version 0.8