Skip to content

Instantly share code, notes, and snippets.

@jarnaldich
Created November 28, 2018 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jarnaldich/0ec82157a48c08d7fe0d89780c606b9e to your computer and use it in GitHub Desktop.
Save jarnaldich/0ec82157a48c08d7fe0d89780c606b9e to your computer and use it in GitHub Desktop.
[Using Text.XML.Lens with namespaces] Example of using namespaces for Text.MXL.Lens #haskell #xml #stack #script
#!/usr/bin/env stack
{-
stack
--install-ghc runghc
--package xml-lens
-}
{-# LANGUAGE OverloadedStrings #-}
module Main where
import System.Environment (getArgs)
import Text.XML
import Text.XML.Lens
elgmd x = el Name { nameLocalName = x, nameNamespace = Just "http://www.isotc211.org/2005/gmd", namePrefix = Nothing }
elgml x = el Name { nameLocalName = x, nameNamespace = Just "http://www.opengis.net/gml", namePrefix = Just "gml" }
main = do
[fname] <- getArgs -- Gross...
doc <- Text.XML.readFile def fname
let lens = root . elgmd "MD_Metadata" ./ elgmd "identificationInfo" ./ elgmd "MD_DataIdentification"
./ elgmd "extent" ./ elgmd "EX_Extent" ./ elgmd "temporalElement" ./ elgmd "EX_TemporalExtent" ./ elgmd "extent"
./ elgml "TimePeriod" ./ elgml "begin"
./ elgml "TimeInstant" ./ elgml "timePosition" . text
putStrLn $ show $ (doc ^. lens)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment