Convert a Puppet hash into XML data.
Convert a Puppet hash into XML data.
hash_to_xml()
given the following data:
$data = {
'?xml version="1.0" encoding="UTF-8"?' => false,
'xml' => {
'fruit' => 'apple',
'vegetables' => {
'green' => 'cucumber',
'brown' => 'potato'
},
'nested' => {
'one' => {
'foo' => 'bar',
},
'two' => {
'foo' => 'bar',
}
}
}
}
file { '/tmp/example.xml':
ensure => file,
content => hash_to_xml($data),
}
The file at /tmp/example.xml
will contain:
<?xml version="1.0" encoding="UTF-8"?>
<xml>
<fruit>apple</fruit>
<vegetables>
<green>cucumber</green>
<brown>potato</brown>
</vegetables>
<nested>
<one>
<foo>bar</foo>
</one>
<two>
<foo>bar</foo>
</two>
</nested>
</xml>
-
data
Puppet hash of intended XML data. Keys set to strings will be XML values like this:
'key' => 'value'
converts to `value``Keys set to hashes create opening and closing tags like this:
parent => { ... }
converts to<parent>...</parent>
Keys set to
false
will open but not close like this:?xml version="1.0" encoding="UTF-8"?' => false
converts to<?xml version="1.0" encoding="UTF-8"?>
Required
-
indent
Starting indent in case you want to nest generated XML into other XML.
Default:
0
-
indent character
Chracter used for indent. Can be used to choose between tabs, spaces, etc.
Default:
\s
-
indent character count
The number of indent characters to use. Can be used to decide 4 spaces, 2 tabs, etc.
Default:
2
Type: rvalue
This repositority is largely the work of some Puppet community members. It is not officially maintained by Puppet, or any individual in particular. Issues should be opened in Github. Questions should be directed at the individuals responsible for committing that particular code.