Created
April 7, 2015 08:17
-
-
Save ip1981/5a97a340f783a2552466 to your computer and use it in GitHub Desktop.
Yet another HXT example
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
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