Arrows for processing XmlTrees
These arrows can be grouped into predicates, selectors, constructors, and transformers.
All predicates (tests) act like Control.Arrow.ArrowIf.none for failure and Control.Arrow.ArrowIf.this for success.
A logical and can be formed by a1 >>> a2 , a locical or by a1 <+> a2 .
Selector arrows will fail, when applied to wrong input, e.g. selecting the text of a node with getText will fail when applied to a none text node.
Edit arrows will remain the input unchanged, when applied to wrong argument, e.g. editing the content of a text node with changeText applied to an element node will return the unchanged element node.
Methods
isText :: a XmlTree XmlTreetest for text nodes
isBlob :: a XmlTree XmlTreeisCharRef :: a XmlTree XmlTreetest for char reference, used during parsing
isEntityRef :: a XmlTree XmlTreetest for entity reference, used during parsing
isCmt :: a XmlTree XmlTreetest for comment
isCdata :: a XmlTree XmlTreetest for CDATA section, used during parsing
isPi :: a XmlTree XmlTreetest for processing instruction
isXmlPi :: a XmlTree XmlTreetest for processing instruction <?xml ...>
isElem :: a XmlTree XmlTreetest for element
isDTD :: a XmlTree XmlTreetest for DTD part, used during parsing
isAttr :: a XmlTree XmlTreetest for attribute tree
isError :: a XmlTree XmlTreetest for error message
isRoot :: a XmlTree XmlTreetest for root node (element with name "/")
hasText :: (String -> Bool) -> a XmlTree XmlTreetest for text nodes with text, for which a predicate holds
example:
hasText (all (`elem` " \t\n"))check for text nodes with only whitespace contentisWhiteSpace :: a XmlTree XmlTreetest for text nodes with only white space
implemented with
hasTesthasNameWith :: (QName -> Bool) -> a XmlTree XmlTreetest whether a node (element, attribute, pi) has a name with a special property
hasQName :: QName -> a XmlTree XmlTreetest whether a node (element, attribute, pi) has a specific qualified name useful only after namespace propagation
hasName :: String -> a XmlTree XmlTreetest whether a node has a specific name (prefix:localPart or localPart), generally useful, even without namespace handling
hasLocalPart :: String -> a XmlTree XmlTreetest whether a node has a specific name as local part, useful only after namespace propagation
hasNamePrefix :: String -> a XmlTree XmlTreetest whether a node has a specific name prefix, useful only after namespace propagation
hasNamespaceUri :: String -> a XmlTree XmlTreetest whether a node has a specific namespace URI useful only after namespace propagation
hasAttr :: String -> a XmlTree XmlTreetest whether an element node has an attribute node with a specific name
hasQAttr :: QName -> a XmlTree XmlTreetest whether an element node has an attribute node with a specific qualified name
hasAttrValue :: String -> (String -> Bool) -> a XmlTree XmlTreetest whether an element node has an attribute with a specific value
hasQAttrValue :: QName -> (String -> Bool) -> a XmlTree XmlTreetest whether an element node has an attribute with a qualified name and a specific value
mkText :: a String XmlTreetext node construction arrow
mkBlob :: a Blob XmlTreeblob node construction arrow
mkCharRef :: a Int XmlTreechar reference construction arrow, useful for document output
mkEntityRef :: a String XmlTreeentity reference construction arrow, useful for document output
mkCmt :: a String XmlTreecomment node construction, useful for document output
mkCdata :: a String XmlTreeCDATA construction, useful for document output
mkError :: Int -> a String XmlTreeerror node construction, useful only internally
mkElement :: QName -> a n XmlTree -> a n XmlTree -> a n XmlTreeelement construction: | the attributes and the content of the element are computed by applying arrows to the input
mkAttr :: QName -> a n XmlTree -> a n XmlTreeattribute node construction: | the attribute value is computed by applying an arrow to the input
mkPi :: QName -> a n XmlTree -> a n XmlTreeprocessing 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 XmlTreemkelem :: String -> [a n XmlTree] -> [a n XmlTree] -> a n XmlTreeaelem :: String -> [a n XmlTree] -> a n XmlTreeselem :: String -> [a n XmlTree] -> a n XmlTreeeelem :: String -> a n XmlTreeroot :: [a n XmlTree] -> [a n XmlTree] -> a n XmlTreeconstruction of an element node with name "/" for document roots
qattr :: QName -> a n XmlTree -> a n XmlTreealias for mkAttr
attr :: String -> a n XmlTree -> a n XmlTreeconvenient arrow for attribute construction, simple variant of mkAttr
txt :: String -> a n XmlTreeconstant arrow for text nodes
blb :: Blob -> a n XmlTreeconstant arrow for blob nodes
charRef :: Int -> a n XmlTreeconstant arrow for char reference nodes
entityRef :: String -> a n XmlTreeconstant arrow for entity reference nodes
cmt :: String -> a n XmlTreeconstant arrow for comment
warn :: String -> a n XmlTreeconstant arrow for warning
err :: String -> a n XmlTreeconstant arrow for errors
fatal :: String -> a n XmlTreeconstant arrow for fatal errors
spi :: String -> String -> a n XmlTreeconstant arrow for simple processing instructions, see mkPi
sqattr :: QName -> String -> a n XmlTreesattr :: String -> String -> a n XmlTreeconstant arrow for attribute nodes, attribute name and value are | given by parameters, see mkAttr
getText :: a XmlTree Stringselect the text of a text node
getCharRef :: a XmlTree Intselect the value of a char reference
getEntityRef :: a XmlTree Stringselect the name of a entity reference node
getCmt :: a XmlTree Stringselect the comment of a comment node
getCdata :: a XmlTree Stringselect the content of a CDATA node
getPiName :: a XmlTree QNameselect the name of a processing instruction
getPiContent :: a XmlTree XmlTreeselect the content of a processing instruction
getElemName :: a XmlTree QNameselect the name of an element node
getAttrl :: a XmlTree XmlTreeselect the attribute list of an element node
getDTDPart :: a XmlTree DTDElemselect the DTD type of a DTD node
getDTDAttrl :: a XmlTree Attributesselect the DTD attributes of a DTD node
getAttrName :: a XmlTree QNameselect the name of an attribute
getErrorLevel :: a XmlTree Intselect the error level (c_warn, c_err, c_fatal) from an error node
getErrorMsg :: a XmlTree Stringselect the error message from an error node
getQName :: a XmlTree QNameselect the qualified name from an element, attribute or pi
getName :: a XmlTree Stringselect the prefix:localPart or localPart from an element, attribute or pi
getUniversalName :: a XmlTree Stringselect the univeral name ({namespace URI} ++ localPart)
getUniversalUri :: a XmlTree Stringselect the univeral name (namespace URI ++ localPart)
getLocalPart :: a XmlTree Stringselect the local part
getNamePrefix :: a XmlTree Stringselect the name prefix
getNamespaceUri :: a XmlTree Stringselect the namespace URI
getAttrValue :: String -> a XmlTree Stringselect the value of an attribute of an element node, always succeeds with empty string as default value ""
getAttrValue0 :: String -> a XmlTree Stringlike getAttrValue, but fails if the attribute does not exist
getQAttrValue :: QName -> a XmlTree Stringlike 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 Stringlike getQAttrValue, but fails if attribute does not exist
changeText :: (String -> String) -> a XmlTree XmlTreeedit the string of a text node
changeBlob :: (Blob -> Blob) -> a XmlTree XmlTreeedit the blob of a blob node
changeCmt :: (String -> String) -> a XmlTree XmlTreeedit the comment string of a comment node
changeQName :: (QName -> QName) -> a XmlTree XmlTreeedit an element-, attribute- or pi- name
changeElemName :: (QName -> QName) -> a XmlTree XmlTreeedit an element name
changeAttrName :: (QName -> QName) -> a XmlTree XmlTreeedit an attribute name
changePiName :: (QName -> QName) -> a XmlTree XmlTreeedit a pi name
changeAttrValue :: (String -> String) -> a XmlTree XmlTreeedit an attribute value
changeAttrl :: (XmlTrees -> XmlTrees -> XmlTrees) -> a XmlTree XmlTree -> a XmlTree XmlTreeedit an attribute list of an element node
setQName :: QName -> a XmlTree XmlTreereplace an element, attribute or pi name
setElemName :: QName -> a XmlTree XmlTreereplace an element name
setAttrName :: QName -> a XmlTree XmlTreereplace an attribute name
setPiName :: QName -> a XmlTree XmlTreereplace an element name
setAttrl :: a XmlTree XmlTree -> a XmlTree XmlTreereplace an atribute list of an element node
addAttrl :: a XmlTree XmlTree -> a XmlTree XmlTreeadd a list of attributes to an element
addAttr :: String -> String -> a XmlTree XmlTreeadd (or replace) an attribute
removeAttr :: String -> a XmlTree XmlTreeremove an attribute
removeQAttr :: QName -> a XmlTree XmlTreeremove an attribute with a qualified name
processAttrl :: a XmlTree XmlTree -> a XmlTree XmlTreeprocess the attributes of an element node with an arrow
processTopDownWithAttrl :: a XmlTree XmlTree -> a XmlTree XmlTreeprocess a whole tree inclusive attribute list of element nodes see also: processTopDown
(+=) :: a b XmlTree -> a b XmlTree -> a b XmlTreeinfixl 7convenient op for adding attributes or children to a node
usage:
tf += cfthe
tfarrow computes an element node, and all trees computed bycfare 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
tfcomputes 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 Stringapply an arrow to the input and convert the resulting XML trees into a string representation
xshowBlob :: a n XmlTree -> a n Blobapply an arrow to the input and convert the resulting XML trees into a string representation