~singpolyma/xml-types-haskell

34b9b9466e22373c7822ebe61d52d16cce3876e4 — John Millikin 11 years ago f2ffe34 + ab16064 xml-types_0.3
Version 0.3
2 files changed, 12 insertions(+), 37 deletions(-)

M Data/XML/Types.hs
M xml-types.cabal
M Data/XML/Types.hs => Data/XML/Types.hs +11 -35
@@ 36,8 36,6 @@ module Data.XML.Types
	-- ** Doctypes
	, Doctype (..)
	, ExternalID (..)
	, DoctypeNode (..)
	, Declaration
	
	-- ** Incremental processing
	, Event (..)


@@ 68,7 66,6 @@ module Data.XML.Types
	, attributeText
	) where
import Control.Monad ((>=>))
import qualified Data.Map as M
import Data.Maybe (isJust)
import Data.Text (Text)
import qualified Data.Text as T


@@ 126,7 123,7 @@ instance Typeable Node where

data Element = Element
	{ elementName :: Name
	, elementAttributes :: M.Map Name [Content]
	, elementAttributes :: [(Name, [Content])]
	, elementNodes :: [Node]
	}
	deriving (Show, Eq)


@@ 180,15 177,17 @@ instance IsString Name where
		(ns, local) -> Name (T.pack (drop 1 local)) (Just (T.pack ns)) Nothing
	fromString local = Name (T.pack local) Nothing Nothing

-- | Note: due to the incredible complexity of DTDs, this type only supports
-- external subsets. I've tried adding internal subset types, but they
-- quickly gain more code than the rest of this module put together.
--
-- It is possible that some future version of this library might support
-- internal subsets, but I am no longer actively working on adding them.
data Doctype = Doctype
	{ doctypeName :: Text
	, doctypeExternalID :: Maybe ExternalID
	, doctypeNodes :: [DoctypeNode]
	, doctypeID :: Maybe ExternalID
	}
	deriving (Show, Eq)

instance Ord Doctype where
	compare = compare `on` (\x -> (doctypeName x, doctypeExternalID x))
	deriving (Show, Eq, Ord)

instance Typeable Doctype where
	typeOf = typeString "Doctype"


@@ 201,28 200,6 @@ data ExternalID
instance Typeable ExternalID where
	typeOf = typeString "ExternalID"

data DoctypeNode
	= DoctypeDeclaration Declaration
	| DoctypeInstruction Instruction
	| DoctypeComment Text
	deriving (Show, Eq)

instance Typeable DoctypeNode where
	typeOf = typeString "DoctypeNode"

-- | Internal doctype declarations are still largely unimplemented. This
-- type will be populated and published in a later version of @xml-types@.
--
data Declaration
	= DeclareElement Text
	| DeclareAttributeList Text
	| DeclareEntity Text
	| DeclareNotation Text
	deriving (Show, Eq)

instance Typeable Declaration where
	typeOf = typeString "Declaration"

-- | Some XML processing tools are incremental, and work in terms of events
-- rather than node trees. The 'Event' type allows a document to be fully
-- specified as a sequence of events.


@@ 239,10 216,9 @@ data Event
	= EventBeginDocument
	| EventEndDocument
	| EventBeginDoctype Text (Maybe ExternalID)
	| EventDeclaration Declaration
	| EventEndDoctype
	| EventInstruction Instruction
	| EventBeginElement Name (M.Map Name [Content])
	| EventBeginElement Name [(Name, [Content])]
	| EventEndElement Name
	| EventContent Content
	| EventComment Text


@@ 296,7 272,7 @@ hasAttributeText :: Name -> (Text -> Bool) -> Element -> [Element]
hasAttributeText name p e = [e | maybe False p (attributeText name e)]

attributeContent :: Name -> Element -> Maybe [Content]
attributeContent name e = M.lookup name (elementAttributes e)
attributeContent name e = lookup name (elementAttributes e)

attributeText :: Name -> Element -> Maybe Text
attributeText name e = fmap contentFlat (attributeContent name e)

M xml-types.cabal => xml-types.cabal +1 -2
@@ 1,5 1,5 @@
name: xml-types
version: 0.2
version: 0.3
synopsis: Basic types for representing XML
license: MIT
license-file: license.txt


@@ 21,7 21,6 @@ library
  build-depends:
      base >=3 && < 5
    , text
    , containers

  exposed-modules:
    Data.XML.Types