Text.XML.HaXml.Namespaces

HaXml-1.25.3: Utilities for manipulating XML documents

Safe Haskell | Safe
Language | Haskell98

Text.XML.HaXml.Namespaces

Synopsis

- nullNamespace :: Namespace
- expandedName :: QName -> (Maybe Namespace, String)
- namespaceName :: QName -> Maybe Namespace
- localName :: QName -> String
- printableName :: QName -> String
- qualify :: Maybe Namespace -> Map String Namespace -> QName -> QName
- deQualify :: Maybe Namespace -> Map String Namespace -> QName -> QName
- qualifyExceptLocal :: Maybe Namespace -> Map String Namespace -> QName -> QName
- initNamespaceEnv :: Map String Namespace
- augmentNamespaceEnv :: Namespace -> Map String Namespace -> Map String Namespace
- resolveAllNames :: (Maybe Namespace -> Map String Namespace -> QName -> QName) -> Document i -> Document i

# Documentation

nullNamespace :: Namespace

The null Namespace (no prefix, no URI).

expandedName :: QName -> (Maybe Namespace, String)

Every Name can be split into a Namespace and local Name. The Namespace might of course be missing.

namespaceName :: QName -> Maybe Namespace

Return the (possibly absent) Namespace component of a Name.

localName :: QName -> String

Return the local component of a Name, without its Namespace.

printableName :: QName -> String

Return the printable string for a Name, i.e. attaching a prefix for its namespace (if it has one).

qualify :: Maybe Namespace -> Map String Namespace -> QName -> QName

`qualify` splits a Name of the form "pr:nm" into the prefix "pr" and local name "nm", and looks up the prefix in the given environment to determine its Namespace. There may also be a default namespace (the first argument) for unqualified names. In the absence of a default Namespace, a Name that does not have a prefix remains unqualified. A prefix that is not known in the environment becomes a fresh namespace with null URI. A Name that is already qualified is passed unchanged, unless its URI was null, in which case we check afresh for that prefix in the environment.

deQualify :: Maybe Namespace -> Map String Namespace -> QName -> QName

`deQualify` has the same signature as `qualify`, but ignores the arguments for default namespace and environment, and simply removes any pre-existing qualification.

qualifyExceptLocal :: Maybe Namespace -> Map String Namespace -> QName -> QName

`qualifyExceptLocal` converts names to qualified names, except where an existing qualification matches the default namespace, in which case the qualification is removed. (This is useful when translating QNames to Haskell, because Haskell qualified names cannot use the current module name.)

initNamespaceEnv :: Map String Namespace

The initial Namespace environment. It always has bindings for the prefixes `xml` and `xmlns`.

augmentNamespaceEnv :: Namespace -> Map String Namespace -> Map String Namespace

Add a fresh Namespace into the Namespace environment. It is not permitted to rebind the prefixes `xml` or `xmlns`, but that is not checked here.

resolveAllNames :: (Maybe Namespace -> Map String Namespace -> QName -> QName) -> Document i -> Document i

resolveAllNames in a document, causes every name to be properly qualified with its namespace. There is a default namespace for any name that was originally unqualified. This is likely only useful when dealing with parsed document, less useful when generating a document from scratch.