Skip to content

Instantly share code, notes, and snippets.

@dpwiz
Last active December 14, 2015 01:18
Show Gist options
  • Save dpwiz/5004655 to your computer and use it in GitHub Desktop.
Save dpwiz/5004655 to your computer and use it in GitHub Desktop.
-- | Little helper to apply default service namespace to a node and it's descendants.
-- This removes the necessity to flood your code with {http://vendor.silly.web/Service.spamx} in element names.
flowNS :: Maybe Text -> Node -> Node
flowNS ns (NodeElement (Element (Name local Nothing prefix) as cs)) = NodeElement $ Element (Name local ns prefix) as $ map (flowNS ns) cs -- update element ns and continue
flowNS ns (NodeElement (Element name@(Name _ ns' _) as cs)) = NodeElement $ Element name as $ map (flowNS ns') cs -- switch to new namespace and continue
flowNS ns node = node -- ignore non-element nodes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment