-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A light-weight XML library -- -- Light-weight XML library derived from the `xml` package for -- simple parsing and creation of XML documents. It only depends on -- base, deepseq, bytestring, text, -- and text-short. -- -- This library provides support for the following specifications: -- --
@package X @version 0.3.0.0 -- | Basic XML types. module Text.XML.Types type Root = Root' Content -- | Represents the implicit root node of an XML document data Root' cnode Root :: Maybe XmlDeclaration -> MiscNodes -> Maybe (Text, MiscNodes) -> Element' cnode -> MiscNodes -> Root' cnode -- | (optional) XML declaration [rootXmlDeclaration] :: Root' cnode -> Maybe XmlDeclaration -- | Miscellaneous nodes before root element & DOCTYPE declaration [rootPreElem] :: Root' cnode -> MiscNodes -- | optional DOCTYPE declaration and more miscellaneous nodes between -- DOCTYPE and root element [rootDoctype] :: Root' cnode -> Maybe (Text, MiscNodes) -- | The single root document element [rootElement] :: Root' cnode -> Element' cnode -- | Miscellaneous nodes after root element [rootPostElem] :: Root' cnode -> MiscNodes -- | Sequence of "miscellaneous" nodes type MiscNodes = [Either Comment PI] -- | Denotes the <?xml version="1.0" encoding="..." standalone="..." -- ?> declaration data XmlDeclaration XmlDeclaration :: Maybe ShortText -> Maybe Bool -> XmlDeclaration -- | Processing instruction data PI PI :: !ShortText -> !Text -> PI -- | Invariant: MUST not be [Xx][Mm][Ll] [piTarget] :: PI -> !ShortText -- | Invariant: MUST not contain ?> [piData] :: PI -> !Text -- | Represents a XML comment -- -- Invariant: SHOULD not contain -- (occurences of -- -- will be automatically substituted by -~ on serialization) newtype Comment Comment :: Text -> Comment -- | XML content data Content Elem :: Element -> Content Text :: CData -> Content CRef :: !ShortText -> Content Proc :: PI -> Content Comm :: Comment -> Content type Element = Element' Content -- | XML elements data Element' cnode Element :: !QName -> [Attr] -> [cnode] -> Element' cnode [elName] :: Element' cnode -> !QName [elAttribs] :: Element' cnode -> [Attr] [elContent] :: Element' cnode -> [cnode] -- | XML attributes data Attr Attr :: !QName -> !Text -> Attr [attrKey] :: Attr -> !QName [attrVal] :: Attr -> !Text -- | XML CData data CData CData :: !CDataKind -> !Text -> CData [cdVerbatim] :: CData -> !CDataKind [cdData] :: CData -> !Text data CDataKind -- | Ordinary character data; pretty printer escapes &, < etc. CDataText :: CDataKind -- | Unescaped character data; pretty printer embeds it in <![CDATA[.. CDataVerbatim :: CDataKind -- | As-is character data; pretty printer passes it along without any -- escaping or CDATA wrap-up. CDataRaw :: CDataKind -- | A NCName -- -- NB: Among other properties this means that an NCName shall -- never be the empty string. type NCName = ShortText -- | XML (expanded) qualified names data QName QName :: !LName -> !URI -> Maybe NCName -> QName -- | Local name part [qLName] :: QName -> !LName -- | Invariant: the qURI field MUST always be populated with the -- proper namespace. Specifically, entities belonging to the -- http://www.w3.org/2000/xmlns/ or -- http://www.w3.org/XML/1998/namespace must have the qURI -- field accordingly [qURI] :: QName -> !URI -- | Invariant: MUST be a proper NCName [qPrefix] :: QName -> Maybe NCName -- | XML local names -- -- Invariant: MUST be a proper NCName newtype LName LName :: NCName -> LName [unLName] :: LName -> NCName -- | URIs resembling anyURI -- -- Invariant: MUST be a valid URI-reference as defined in -- RFC3986 newtype URI URI :: ShortText -> URI [unURI] :: URI -> ShortText -- | Test for empty URI -- ---- >>> isNullURI (URI mempty) -- True ---- --
-- >>> isNullURI (URI "") -- True ---- --
-- >>> isNullURI (URI " ") -- False --isNullURI :: URI -> Bool -- | Position expressed in number of code-points -- -- A negative value denotes EOF type Pos = Int -- | Blank names blank_name :: QName -- | Blank cdata blank_cdata :: CData -- | Blank elements blank_element :: Element -- | Smart constructor for xmlns:<prefix> = -- <namespace-uri> -- -- Invariant: <namespace-uri> MUST be non-empty for -- non-empty prefixes xmlns_attr :: ShortText -> URI -> Attr -- | Smart constructor for xmlns = [<namespace-uri>|""] -- (i.e. for declaring the default namespace) -- --
-- xmlns_attr "" ns == xmlns_def_attr ns --xmlns_def_attr :: URI -> Attr -- | Convert xmlns Attr into a -- (prefix,namespace-uri) pair; returns Nothing if the -- argument isn't a xmlns attribute. -- -- An empty prefix denotes the default-namespace -- --
-- xmlns_from_attr (xmlns_attr pfx ns) == Just (pfx,ns) --xmlns_from_attr :: Attr -> Maybe (ShortText, URI) instance Data.Traversable.Traversable Text.XML.Types.Root' instance Data.Foldable.Foldable Text.XML.Types.Root' instance GHC.Base.Functor Text.XML.Types.Root' instance GHC.Generics.Generic (Text.XML.Types.Root' cnode) instance Data.Data.Data cnode => Data.Data.Data (Text.XML.Types.Root' cnode) instance GHC.Show.Show cnode => GHC.Show.Show (Text.XML.Types.Root' cnode) instance GHC.Generics.Generic Text.XML.Types.Content instance Data.Data.Data Text.XML.Types.Content instance GHC.Show.Show Text.XML.Types.Content instance Data.Traversable.Traversable Text.XML.Types.Element' instance Data.Foldable.Foldable Text.XML.Types.Element' instance GHC.Base.Functor Text.XML.Types.Element' instance GHC.Generics.Generic (Text.XML.Types.Element' cnode) instance Data.Data.Data cnode => Data.Data.Data (Text.XML.Types.Element' cnode) instance GHC.Show.Show cnode => GHC.Show.Show (Text.XML.Types.Element' cnode) instance GHC.Generics.Generic Text.XML.Types.Attr instance Data.Data.Data Text.XML.Types.Attr instance GHC.Show.Show Text.XML.Types.Attr instance GHC.Classes.Ord Text.XML.Types.Attr instance GHC.Classes.Eq Text.XML.Types.Attr instance GHC.Generics.Generic Text.XML.Types.QName instance Data.Data.Data Text.XML.Types.QName instance GHC.Show.Show Text.XML.Types.QName instance GHC.Generics.Generic Text.XML.Types.URI instance Control.DeepSeq.NFData Text.XML.Types.URI instance Data.String.IsString Text.XML.Types.URI instance Data.Data.Data Text.XML.Types.URI instance GHC.Classes.Eq Text.XML.Types.URI instance GHC.Classes.Ord Text.XML.Types.URI instance GHC.Generics.Generic Text.XML.Types.LName instance Control.DeepSeq.NFData Text.XML.Types.LName instance Data.String.IsString Text.XML.Types.LName instance Data.Data.Data Text.XML.Types.LName instance GHC.Classes.Eq Text.XML.Types.LName instance GHC.Classes.Ord Text.XML.Types.LName instance GHC.Generics.Generic Text.XML.Types.CData instance Data.Data.Data Text.XML.Types.CData instance GHC.Show.Show Text.XML.Types.CData instance GHC.Generics.Generic Text.XML.Types.CDataKind instance Data.Data.Data Text.XML.Types.CDataKind instance GHC.Show.Show Text.XML.Types.CDataKind instance GHC.Classes.Eq Text.XML.Types.CDataKind instance Control.DeepSeq.NFData Text.XML.Types.Comment instance GHC.Generics.Generic Text.XML.Types.Comment instance Data.Data.Data Text.XML.Types.Comment instance GHC.Show.Show Text.XML.Types.Comment instance GHC.Generics.Generic Text.XML.Types.PI instance Data.Data.Data Text.XML.Types.PI instance GHC.Show.Show Text.XML.Types.PI instance GHC.Generics.Generic Text.XML.Types.XmlDeclaration instance Data.Data.Data Text.XML.Types.XmlDeclaration instance GHC.Show.Show Text.XML.Types.XmlDeclaration instance Control.DeepSeq.NFData cnode => Control.DeepSeq.NFData (Text.XML.Types.Root' cnode) instance Control.DeepSeq.NFData Text.XML.Types.Content instance Control.DeepSeq.NFData cnode => Control.DeepSeq.NFData (Text.XML.Types.Element' cnode) instance Control.DeepSeq.NFData Text.XML.Types.Attr instance Control.DeepSeq.NFData Text.XML.Types.QName instance GHC.Classes.Eq Text.XML.Types.QName instance GHC.Classes.Ord Text.XML.Types.QName instance GHC.Show.Show Text.XML.Types.URI instance GHC.Show.Show Text.XML.Types.LName instance Control.DeepSeq.NFData Text.XML.Types.CData instance Control.DeepSeq.NFData Text.XML.Types.CDataKind instance Control.DeepSeq.NFData Text.XML.Types.PI instance Control.DeepSeq.NFData Text.XML.Types.XmlDeclaration module Text.XML.Proc -- | Get the text value of an XML element. This function ignores non-text -- elements, and concatenates all text elements. strContent :: Element -> Text -- | Select only the elements from a list of XML content. onlyElems :: [Content] -> [Element] -- | Select only the elements from a parent. elChildren :: Element -> [Element] -- | Select only the text from a list of XML content. onlyText :: [Content] -> [CData] -- | Find all immediate children with the given name. findChildren :: QName -> Element -> [Element] -- | Filter all immediate children wrt a given predicate. filterChildren :: (Element -> Bool) -> Element -> [Element] -- | Filter all immediate children wrt a given predicate over their names. filterChildrenName :: (QName -> Bool) -> Element -> [Element] -- | Find an immediate child with the given name. findChild :: QName -> Element -> Maybe Element -- | Find an immediate child with the given name. filterChild :: (Element -> Bool) -> Element -> Maybe Element -- | Find an immediate child with name matching a predicate. filterChildName :: (QName -> Bool) -> Element -> Maybe Element -- | Find the left-most occurrence of an element matching given name. findElement :: QName -> Element -> Maybe Element -- | Filter the left-most occurrence of an element wrt. given predicate. filterElement :: (Element -> Bool) -> Element -> Maybe Element -- | Filter the left-most occurrence of an element wrt. given predicate. filterElementName :: (QName -> Bool) -> Element -> Maybe Element -- | Find all non-nested occurances of an element. (i.e., once we have -- found an element, we do not search for more occurances among the -- element's children). findElements :: QName -> Element -> [Element] -- | Find all non-nested occurrences of an element wrt. given predicate. -- (i.e., once we have found an element, we do not search for more -- occurances among the element's children). filterElements :: (Element -> Bool) -> Element -> [Element] -- | Find all non-nested occurences of an element wrt a predicate over -- element names. (i.e., once we have found an element, we do not search -- for more occurances among the element's children). filterElementsName :: (QName -> Bool) -> Element -> [Element] -- | Lookup the value of an attribute. findAttr :: QName -> Element -> Maybe Text -- | Lookup attribute name from list. lookupAttr :: QName -> [Attr] -> Maybe Text -- | Lookup the first attribute whose name satisfies the given predicate. lookupAttrBy :: (QName -> Bool) -> [Attr] -> Maybe Text -- | Lookup the value of the first attribute whose name satisfies the given -- predicate. findAttrBy :: (QName -> Bool) -> Element -> Maybe Text -- | XML cursors for working XML content withing the context of an XML -- document. This implementation is based on the general tree zipper -- written by Krasimir Angelov and Iavor S. Diatchki. -- -- NOTE: The Cursor API has been significantly altered in 0.3.0, -- hence this module's API is to be considered "since 0.3.0" module Text.XML.Cursor data Tag Tag :: QName -> [Attr] -> Tag [tagName] :: Tag -> QName [tagAttribs] :: Tag -> [Attr] getTag :: Element -> Tag setTag :: Tag -> Element -> Element fromTag :: Tag -> [Content] -> Element -- | General cursor type Cursor = Cursor' Content -- | The position of a piece of content in an XML document. data Cursor' content Cur :: content -> [Content] -> [Content] -> Path -> Cursor' content -- | The currently selected content. [current] :: Cursor' content -> content -- | Siblings on the left, closest first. [lefts] :: Cursor' content -> [Content] -- | Siblings on the right, closest first. [rights] :: Cursor' content -> [Content] -- | The contexts of the parent elements of this location. [parents] :: Cursor' content -> Path -- | Parent path (with the root as last element) consisting of list of left -- siblings, parent, and right siblings type Path = [([Content], Tag, [Content])] -- | A cursor for the given (root) element. fromRootElement :: Element -> Cursor' Element -- | Construct cursor from document Root fromRoot :: Root -> Cursor' Element -- | Computes the root element containing this location. -- -- NOTE: The root element might have siblings; see toRoot -- or root if you need to deal with such siblings. toRootElement :: IsContent content => Cursor' content -> Element -- | Constructs the document Root containing this location. -- -- Returns Nothing if invalid top-level "miscellaneous" nodes are -- encountered. toRoot :: IsContent content => Cursor' content -> Maybe Root -- | Generalize content type of current Cursor location upCast :: IsContent content => Cursor' content -> Cursor -- | Specialize content type of current Cursor location downCast :: IsContent content => Cursor -> Maybe (Cursor' content) -- | The parent of the given location. parent :: IsContent content => Cursor' content -> Maybe (Cursor' Element) -- | The top-most parent of the given location. root :: IsContent content => Cursor' content -> Cursor' Element -- | The child with the given index (starting from 0). getChild :: IsContent content => Word -> Cursor' content -> Maybe Cursor -- | The first child of the given location. firstChild :: IsContent content => Cursor' content -> Maybe Cursor -- | The last child of the given location. lastChild :: IsContent content => Cursor' content -> Maybe Cursor -- | The left sibling of the given location. left :: IsContent content => Cursor' content -> Maybe Cursor -- | The right sibling of the given location. right :: IsContent content => Cursor' content -> Maybe Cursor -- | The next position in a left-to-right depth-first traversal of a -- document: either the first child, right sibling, or the right sibling -- of a parent that has one. nextDF :: IsContent content => Cursor' content -> Maybe Cursor -- | The first child that satisfies a predicate. findChild :: IsContent content => (Cursor -> Bool) -> Cursor' content -> Maybe Cursor -- | Find the next left sibling that satisfies a predicate. findLeft :: IsContent content => (Cursor -> Bool) -> Cursor' content -> Maybe Cursor -- | Find the next right sibling that satisfies a predicate. findRight :: IsContent content => (Cursor -> Bool) -> Cursor' content -> Maybe Cursor -- | Perform a depth first search for a descendant that satisfies the given -- predicate. findRec :: IsContent content => (Cursor -> Bool) -> Cursor' content -> Maybe Cursor -- | Are we at the top of the document? isRoot :: Cursor' content -> Bool -- | Are we at the left end of the the document (i.e. the locally left-most -- sibling)? isFirst :: Cursor' content -> Bool -- | Are we at the right end of the document (i.e. the locally right-most -- sibling)? isLast :: Cursor' content -> Bool -- | Are we at the bottom of the document? isLeaf :: IsContent content => Cursor' content -> Bool -- | Do we have a parent? isChild :: Cursor' content -> Bool -- | Do we have children? hasChildren :: IsContent content => Cursor' content -> Bool -- | Get the node index inside the sequence of children/siblings getNodeIndex :: Cursor' content -> Word -- | Insert content to the left of the current position. insertLeft :: IsContent c => c -> Cursor' content -> Cursor' content -- | Insert content to the right of the current position. insertRight :: IsContent c => c -> Cursor' content -> Cursor' content -- | Insert content to the left of the current position. The new content -- becomes the current position. insertGoLeft :: IsContent content2 => content -> Cursor' content2 -> Cursor' content -- | Insert content to the right of the current position. The new content -- becomes the current position. insertGoRight :: IsContent content2 => content -> Cursor' content2 -> Cursor' content -- | Remove the content on the left of the current position, if any. removeLeft :: Cursor' content -> Maybe (Content, Cursor' content) -- | Remove the content on the right of the current position, if any. removeRight :: Cursor' content -> Maybe (Content, Cursor' content) -- | Remove the current element. The new position is the one on the left. removeGoLeft :: Cursor' content -> Maybe Cursor -- | Remove the current element. The new position is the one on the right. removeGoRight :: Cursor' content -> Maybe Cursor -- | Remove the current element. The new position is the parent of the old -- position. removeGoUp :: Cursor' content -> Maybe Cursor instance Data.Traversable.Traversable Text.XML.Cursor.Cursor' instance Data.Foldable.Foldable Text.XML.Cursor.Cursor' instance GHC.Base.Functor Text.XML.Cursor.Cursor' instance Data.Data.Data content => Data.Data.Data (Text.XML.Cursor.Cursor' content) instance GHC.Generics.Generic (Text.XML.Cursor.Cursor' content) instance GHC.Show.Show content => GHC.Show.Show (Text.XML.Cursor.Cursor' content) instance Data.Data.Data Text.XML.Cursor.Tag instance GHC.Generics.Generic Text.XML.Cursor.Tag instance GHC.Show.Show Text.XML.Cursor.Tag instance Control.DeepSeq.NFData content => Control.DeepSeq.NFData (Text.XML.Cursor.Cursor' content) instance Control.DeepSeq.NFData Text.XML.Cursor.Tag -- | Output handling for the lightweight XML lib. module Text.XML.Output -- | Serialize a sequence of XML Content nodes serializeXML :: [Content] -> Text -- | Serialize XML 1.0 document prefixed by the XML prologue "<?xml -- version='1.0' ?>" serializeXMLDoc :: Element -> Text -- | Serialize a XML Root serializeXMLRoot :: SerializeXMLOptions -> Root -> Text -- | Options for tweaking XML serialization output data SerializeXMLOptions SerializeXMLOptions :: (QName -> Bool) -> Bool -> Bool -> SerializeXMLOptions [serializeAllowEmptyTag] :: SerializeXMLOptions -> QName -> Bool [serializeProEpilogAddNLs] :: SerializeXMLOptions -> Bool [serializeSortAttributes] :: SerializeXMLOptions -> Bool -- | Default rendering options -- --