Created
November 28, 2018 14:07
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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