~singpolyma/xml-types-haskell

6d9f573f7478a5524dafd8922f8897c5a2436b00 — John Millikin 13 years ago 0fc848a xml-types_0.1.2
Add support for Clark notation when entering names.
2 files changed, 15 insertions(+), 1 deletions(-)

M Data/XML/Types.hs
M xml-types.cabal
M Data/XML/Types.hs => Data/XML/Types.hs +14 -0
@@ 60,6 60,8 @@ module Data.XML.Types
	) where
import Control.Monad ((>=>))
import Data.Text.Lazy (Text)
import qualified Data.Text.Lazy as T
import Data.String (IsString, fromString)

data Document = Document
	{ documentPrologue :: Prologue


@@ 111,6 113,11 @@ data Content
	| ContentEntity Text
	deriving (Show, Eq)

-- | The 'Eq' instance for 'Name' ignores prefixes.
--
-- The 'IsString' instance for 'Name' allows entry using Clark notation;
-- see <http://www.jclark.com/xml/xmlns.htm> and
-- <http://infohost.nmt.edu/tcc/help/pubs/pylxml/etree-QName.html>
data Name = Name
	{ nameLocalName :: Text
	, nameNamespace :: Maybe Text


@@ 125,6 132,13 @@ instance Eq Name where
		, nameNamespace x == nameNamespace y
		]

instance IsString Name where
	fromString "" = Name T.empty Nothing Nothing
	fromString full@('{':rest) = case break (== '}') rest of
		(_, "") -> error ("Invalid Clark notation: " ++ show full)
		(ns, local) -> Name (T.pack (drop 1 local)) (Just (T.pack ns)) Nothing
	fromString local = Name (T.pack local) Nothing Nothing

class Named a where
	getName :: a -> Name


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