Module XML

Library for processing XML data.

Warning: the structure of this library is not stable and might be changed in the future!

Author: Michael Hanus

Version: September 2017

Summary of exported operations:

tagOf :: XmlExp -> String   
Returns the tag of an XML element (or empty for a textual element).
elemsOf :: XmlExp -> [XmlExp]   
Returns the child elements an XML element.
textOf :: [XmlExp] -> String   
Extracts the textual contents of a list of XML expressions.
textOfXml :: [XmlExp] -> String   
Included for backward compatibility, better use textOf!
xtxt :: String -> XmlExp   
Basic text (maybe containing special XML chars).
xml :: String -> [XmlExp] -> XmlExp   
XML element without attributes.
writeXmlFile :: String -> XmlExp -> IO ()   
Writes a file with a given XML document.
writeXmlFileWithParams :: String -> [XmlDocParams] -> XmlExp -> IO ()   
Writes a file with a given XML document and XML parameters.
showXmlDoc :: XmlExp -> String   
Show an XML document in indented format as a string.
showXmlDocWithParams :: [XmlDocParams] -> XmlExp -> String   
readXmlFile :: String -> IO XmlExp   
Reads a file with an XML document and returns the corresponding XML expression.
readUnsafeXmlFile :: String -> IO (Maybe XmlExp)   
Tries to read a file with an XML document and returns the corresponding XML expression, if possible.
readFileWithXmlDocs :: String -> IO [XmlExp]   
Reads a file with an arbitrary sequence of XML documents and returns the list of corresponding XML expressions.
parseXmlString :: String -> [XmlExp]   
Transforms an XML string into a list of XML expressions.
updateXmlFile :: (XmlExp -> XmlExp) -> String -> IO ()   
An action that updates the contents of an XML file by some transformation on the XML document.

Exported datatypes:


XmlExp

The data type for representing XML expressions.

Constructors:

  • XText :: String -> XmlExp : a text string (PCDATA)
  • XElem :: String -> [(String,String)] -> [XmlExp] -> XmlExp : an XML element with tag field, attributes, and a list of XML elements as contents

Encoding

The data type for encodings used in the XML document.

Constructors:

  • StandardEnc :: Encoding
  • Iso88591Enc :: Encoding

XmlDocParams

The data type for XML document parameters.

Constructors:

  • Enc :: Encoding -> XmlDocParams : the encoding for a document
  • DtdUrl :: String -> XmlDocParams : the url of the DTD for a document

Exported operations:

tagOf :: XmlExp -> String   

Returns the tag of an XML element (or empty for a textual element).

Further infos:
  • solution complete, i.e., able to compute all solutions

elemsOf :: XmlExp -> [XmlExp]   

Returns the child elements an XML element.

Further infos:
  • solution complete, i.e., able to compute all solutions

textOf :: [XmlExp] -> String   

Extracts the textual contents of a list of XML expressions. Useful auxiliary function when transforming XML expressions into other data structures.

For instance, textOf [XText "xy", XElem "a" [] [], XText "bc"] == "xy bc"

textOfXml :: [XmlExp] -> String   

Included for backward compatibility, better use textOf!

xtxt :: String -> XmlExp   

Basic text (maybe containing special XML chars).

Further infos:
  • solution complete, i.e., able to compute all solutions

xml :: String -> [XmlExp] -> XmlExp   

XML element without attributes.

Further infos:
  • solution complete, i.e., able to compute all solutions

writeXmlFile :: String -> XmlExp -> IO ()   

Writes a file with a given XML document.

writeXmlFileWithParams :: String -> [XmlDocParams] -> XmlExp -> IO ()   

Writes a file with a given XML document and XML parameters.

showXmlDoc :: XmlExp -> String   

Show an XML document in indented format as a string.

showXmlDocWithParams :: [XmlDocParams] -> XmlExp -> String   

readXmlFile :: String -> IO XmlExp   

Reads a file with an XML document and returns the corresponding XML expression.

readUnsafeXmlFile :: String -> IO (Maybe XmlExp)   

Tries to read a file with an XML document and returns the corresponding XML expression, if possible. If file or parse errors occur, Nothing is returned.

readFileWithXmlDocs :: String -> IO [XmlExp]   

Reads a file with an arbitrary sequence of XML documents and returns the list of corresponding XML expressions.

parseXmlString :: String -> [XmlExp]   

Transforms an XML string into a list of XML expressions. If the XML string is a well structured document, the list of XML expressions should contain exactly one element.

updateXmlFile :: (XmlExp -> XmlExp) -> String -> IO ()   

An action that updates the contents of an XML file by some transformation on the XML document.

Example call:
(updateXmlFile f file)
Parameters:
  • f : the function to transform the XML document in the file
  • file : the name of the XML file