~singpolyma/xml-types-haskell

997fda1cfebf3938656b8f30c49b2ecb83b09698 — John Millikin 11 years ago 4eebb86
Store element attributes as (Map Name [Content])
2 files changed, 11 insertions(+), 11 deletions(-)

M Data/XML/Types.hs
M xml-types.cabal
M Data/XML/Types.hs => Data/XML/Types.hs +10 -11
@@ 32,7 32,6 @@ module Data.XML.Types
	-- ** Document body
	, Node (..)
	, Element (..)
	, Attribute (..)
	, Content (..)
	, Name (..)
	


@@ 55,9 54,12 @@ module Data.XML.Types
	, nodeChildren
	, elementChildren
	, elementContent
	, attributeContent
	, hasAttribute
	) where
import Control.Monad ((>=>))
import qualified Data.Map as M
import Data.Maybe (isJust)
import Data.Text (Text)
import qualified Data.Text as T
import Data.String (IsString, fromString)


@@ 97,17 99,11 @@ data Node

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

data Attribute = Attribute
	{ attributeName :: Name
	, attributeContent :: [Content]
	}
	deriving (Show, Eq)

data Content
	= ContentText Text
	| ContentEntity Text


@@ 171,7 167,7 @@ data Event
	| EventEndDocument
	| EventInstruction Instruction
	| EventDoctype Doctype
	| EventBeginElement Name [Attribute]
	| EventBeginElement Name (M.Map Name [Content])
	| EventEndElement Name
	| EventContent Content
	| EventComment Text


@@ 206,5 202,8 @@ elementContent = elementNodes >=> isContent
nodeChildren :: Node -> [Node]
nodeChildren = isElement >=> elementNodes

hasAttribute :: (Attribute -> [Attribute]) -> Element -> [Element]
hasAttribute f e = [e | not $ null (elementAttributes e >>= f)]
hasAttribute :: Name -> Element -> [Element]
hasAttribute name e = [e | isJust (attributeContent name e)]

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

M xml-types.cabal => xml-types.cabal +1 -0
@@ 21,6 21,7 @@ library
  build-depends:
      base >=3 && < 5
    , text
    , containers

  exposed-modules:
    Data.XML.Types