Skip to content

Instantly share code, notes, and snippets.

@ip1981
Created April 7, 2015 08:17
Show Gist options
  • Save ip1981/5a97a340f783a2552466 to your computer and use it in GitHub Desktop.
Save ip1981/5a97a340f783a2552466 to your computer and use it in GitHub Desktop.
Yet another HXT example
import Text.XML.HXT.Core
main = runX $
readDocument [ withValidate no ] "in.xml" >>> addRuntimeScope >>>
writeDocument [ withIndent yes ] "out.xml"
addRuntimeScope = processTopDown (runtimeScope `when` noScope)
runtimeScope = replaceChildren (getChildren <+> scope) where
scope = mkelem "scope" [] [ txt "runtime" ]
noScope = isElem >>> hasName "dependency" >>>
neg ( getChildren >>> isElem >>> hasName "scope" )
-- in.xml
-- <?xml version="1.0" encoding="UTF-8"?>
-- <dependencies>
-- <dependency>
-- <artefactId>foo</artefactId>
-- <scope>test</scope>
-- </dependency>
-- <dependency>
-- <artefactId>bar</artefactId>
-- </dependency>
-- <dependency>
-- <artefactId>baz</artefactId>
-- <scope>runtime</scope>
-- </dependency>
-- </dependencies>
-- out.xml
-- <?xml version="1.0" encoding="UTF-8"?>
-- <dependencies>
-- <dependency>
-- <artefactId>foo</artefactId>
-- <scope>test</scope>
-- </dependency>
-- <dependency>
-- <artefactId>bar</artefactId>
-- <scope>runtime</scope> <!-- here -->
-- </dependency>
-- <dependency>
-- <artefactId>baz</artefactId>
-- <scope>runtime</scope>
-- </dependency>
-- </dependencies>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment