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: June 2018

Summary of exported operations:

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

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

Returns the child elements an XML element.

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

textOf :: [XmlExp] -> String  Deterministic 

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

For instance, codetextOf [XText "xy", XElem "a" [] [], XText "bc"] == "xy bc"/code

textOfXml :: [XmlExp] -> String  Deterministic 

Included for backward compatibility, better use codetextOf/code!

xtxt :: String -> XmlExp  Deterministic 

Basic text (maybe containing special XML chars).

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

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

XML element without attributes.

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

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

Writes a file with a given XML document.

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

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

showXmlDoc :: XmlExp -> String  Deterministic 

Show an XML document in indented format as a string.

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

readXmlFile :: String -> IO XmlExp  Non-deterministic 

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

readUnsafeXmlFile :: String -> IO (Maybe XmlExp)  Non-deterministic 

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]  Non-deterministic 

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

parseXmlString :: String -> [XmlExp]  Non-deterministic 

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 ()  Non-deterministic 

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