Copyright | Copyright (C) 2005-2013 Uwe Schmidt |
---|---|
License | MIT |
Maintainer | Uwe Schmidt (uwe@fh-wedel.de) |
Stability | stable |
Portability | portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Compound arrows for reading an XML/HTML document or an XML/HTML string
Synopsis
- readDocument :: SysConfigList -> String -> IOStateArrow s b XmlTree
- readFromDocument :: SysConfigList -> IOStateArrow s String XmlTree
- readString :: SysConfigList -> String -> IOStateArrow s b XmlTree
- readFromString :: SysConfigList -> IOStateArrow s String XmlTree
- hread :: ArrowXml a => a String XmlTree
- hreadDoc :: ArrowXml a => a String XmlTree
- xread :: ArrowXml a => a String XmlTree
- xreadDoc :: ArrowXml a => a String XmlTree
Documentation
readDocument :: SysConfigList -> String -> IOStateArrow s b XmlTree Source #
the main document input filter
this filter can be configured by a list of configuration options,
a value of type SysConfig
for all available options see module SystemConfig
withValidate yes/no
: switch on/off DTD validation. Only for XML parsed documents, not for HTML parsing.withSubstDTDEntities yes/no
: switch on/off entity substitution for general entities defined in DTD validation. Default isyes
. Switching this option and the validation off can lead to faster parsing, in that case reading the DTD documents is not longer necessary. Only used with XML parsed documents, not with HTML parsing.withSubstHTMLEntities yes/no
: switch on/off entity substitution for general entities defined in HTML validation. Default isno
. Switching this option on and the validation and substDTDEntities off can lead to faster parsing, in that case reading the DTD documents is not longer necessary, HTML general entities are still substituted. Only used with XML parsed documents, not with HTML parsing.withParseHTML yes/no
: switch on HTML parsing.withParseByMimeType yes/no
: select XML/HTML parser by document mime type. text/xml and text/xhtml are parsed as XML, text/html as HTML.withCheckNamespaces yes/no
: Switch on/off namespace propagation and checkingwithInputEncoding <encoding-spec>
: Set default encoding.withTagSoup
: use light weight and lazy parser based on tagsoup lib. This is only available when package hxt-tagsoup is installed and the source contains animport Text.XML.HXT.TagSoup
.withRelaxNG <schema.rng>
: validate document with Relax NG, the parameter is for the schema URI. This implies using XML parser, no validation against DTD, and canonicalisation.withCurl [<curl-option>...]
: Use the libCurl binding for HTTP access. This is only available when package hxt-curl is installed and the source contains animport Text.XML.HXT.Curl
.withHTTP [<http-option>...]
: Use the Haskell HTTP package for HTTP access. This is only available when package hxt-http is installed and the source contains animport Text.XML.HXT.HTTP
.
examples:
readDocument [] "test.xml"
reads and validates a document "test.xml", no namespace propagation, only canonicalization is performed
... import Text.XML.HXT.Curl ... readDocument [ withValidate no , withInputEncoding isoLatin1 , withParseByMimeType yes , withCurl [] ] "http://localhost/test.php"
reads document "test.php", parses it as HTML or XML depending on the mimetype given from the server, but without validation, default encoding isoLatin1
.
HTTP access is done via libCurl.
readDocument [ withParseHTML yes , withInputEncoding isoLatin1 ] ""
reads a HTML document from standard input, no validation is done when parsing HTML, default encoding is isoLatin1
,
readDocument [ withInputEncoding isoLatin1 , withValidate no , withMimeTypeFile "/etc/mime.types" , withStrictInput yes ] "test.svg"
reads an SVG document from "test.svg", sets the mime type by looking in the system mimetype config file,
default encoding is isoLatin1
,
... import Text.XML.HXT.Curl import Text.XML.HXT.TagSoup ... readDocument [ withParseHTML yes , withTagSoup , withProxy "www-cache:3128" , withCurl [] , withWarnings no ] "http://www.haskell.org/"
reads Haskell homepage with HTML parser, ignoring any warnings (at the time of writing, there were some HTML errors), with http access via libCurl interface and proxy "www-cache" at port 3128, parsing is done with tagsoup HTML parser. This requires packages "hxt-curl" and "hxt-tagsoup" to be installed
readDocument [ withValidate yes , withCheckNamespaces yes , withRemoveWS yes , withTrace 2 , withHTTP [] ] "http://www.w3c.org/"
read w3c home page (xhtml), validate and check namespaces, remove whitespace between tags, trace activities with level 2. HTTP access is done with Haskell HTTP package
readDocument [ withValidate no , withSubstDTDEntities no ... ] "http://www.w3c.org/"
read w3c home page (xhtml), but without accessing the DTD given in that document. Only the predefined XML general entity refs are substituted.
readDocument [ withValidate no , withSubstDTDEntities no , withSubstHTMLEntities yes ... ] "http://www.w3c.org/"
same as above, but with substituion of all general entity refs defined in XHTML.
for minimal complete examples see writeDocument
and runX
, the main starting point for running an XML arrow.
readFromDocument :: SysConfigList -> IOStateArrow s String XmlTree Source #
the arrow version of readDocument
, the arrow input is the source URI
readString :: SysConfigList -> String -> IOStateArrow s b XmlTree Source #
read a document that is stored in a normal Haskell String
the same function as readDocument, but the parameter forms the input.
All options available for readDocument
are applicable for readString,
except input encoding options.
Encoding: No decoding is done, the String argument is taken as Unicode string All decoding must be done before calling readString, even if the XML document contains an encoding spec.
readFromString :: SysConfigList -> IOStateArrow s String XmlTree Source #
the arrow version of readString
, the arrow input is the source URI
hread :: ArrowXml a => a String XmlTree Source #
parse a string as HTML content, substitute all HTML entity refs and canonicalize tree. (substitute char refs, ...). Errors are ignored.
This arrow delegates all work to the parseHtmlContent parser in module HtmlParser.
This is a simpler version of readFromString
without any options,
but it does not run in the IO monad.
hreadDoc :: ArrowXml a => a String XmlTree Source #
like hread, but accepts a whole document, not a HTML content