I am a adding a couple of simple elements to a bunch of XML files (plists). The existing XML element I am working on looks like this:
<dict>
<key>background</key>
<string>#FFFFFF</string>
<key>caret</key>
<string>#000000</string>
<key>foreground</key>
<string>#000000</string>
<key>invisibles</key>
<string>#BFBFBF</string>
<key>lineHighlight</key>
<string>#00000012</string>
<key>selection</key>
<string>#BAD6FD</string>
</dict>
I have captured this element in an object called settings
and I am adding new <key>
and <string>
elements, and adding some text to those elements. Simple enough so far:
settings.add_element('key').add_text('gutter')
settings.add_element('string').add_text('#282828')
Trouble is, when I write this back out, the XML looks like this (note the last line):
<dict>
<key>background</key>
<string>#FFFFFF</string>
<key>caret</key>
<string>#000000</string>
<key>foreground</key>
<string>#000000</string>
<key>invisibles</key>
<string>#BFBFBF</string>
<key>lineHighlight</key>
<string>#00000012</string>
<key>selection</key>
<string>#BAD6FD</string>
<key>gutter</key><string>#282828</string></dict>
I am using the write (REXML::Document)
method to write out the XML (to $stdout at the moment):
tmtheme.write( $stdout )
Also tried
tmtheme.write( $stdout, 2 )
But these don't return the desired results. The following looked promising:
tmtheme.write( $stdout, 2, true )
But this gives me a known error. Update: just tried it on Ruby 1.9 and although I don't get the erro, it doesn't help - I still get the formatting as seen in the example above.
Can anyone tell me how I can format the XML so that it conforms to the formatting style of the rest of the document? It doesn't necessarily need to be done with REXML.