-
-
Save bluepapa32/872612 to your computer and use it in GitHub Desktop.
Map -> XML 変換
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
def kvmap = [ | |
key1: "value1", | |
key2: "value2", | |
key3: [ | |
"key3-1" : "value3-1", | |
"key3-2" : "value3-2", | |
], | |
] | |
sw = new StringWriter() | |
xml = new groovy.xml.MarkupBuilder(sw); | |
xml.doubleQuotes = true | |
xml.langs(type: 'current') { visit kvmap } | |
def visit(Map m) { m.each { k, v -> xml."$k" { visit v } } } | |
def visit(String s) { xml.mkp.yield s } | |
def expect = '''\ | |
<langs type="current"> | |
<key1>value1</key1> | |
<key2>value2</key2> | |
<key3> | |
<key3-1>value3-1</key3-1> | |
<key3-2>value3-2</key3-2> | |
</key3> | |
</langs>''' | |
assert sw.toString() == expect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment