B
Bucco
I have an xml file that looks something like this:
<action>
<date item="052906">
<task>Some task</task>
<task>Some other task</task>
</date>
<date item="053006">
... more tasks
</date>
</action>
I am trying to sort these task files into yaml that looks like this:
---
date:
052906:
- Some task
- Some other task
.... and so on for each date/task
I have done the following so far:
require 'xmlsimple'
require 'yaml'
doc = XmlSimple.xml_in("Some file.xml", {'KeyAttr' => 'item'})
puts doc.to_yaml
Although this prints out the correct format, the dates are unsorted.
And some of the dates are in quotes while others are not quoted in the
yaml output. I also tried the follwoing:
puts doc.sort.to_yaml
This sorts the hash into multiple arrays which then adds extra dashes
to the yaml output, but the date order is sorted correctly.
So my question is how to sort the hash so that the dates are read in
the correct order when outputted to yaml, but also keep the hash format
and not convert it to an array to sort?
Thanks in advance
SA
<action>
<date item="052906">
<task>Some task</task>
<task>Some other task</task>
</date>
<date item="053006">
... more tasks
</date>
</action>
I am trying to sort these task files into yaml that looks like this:
---
date:
052906:
- Some task
- Some other task
.... and so on for each date/task
I have done the following so far:
require 'xmlsimple'
require 'yaml'
doc = XmlSimple.xml_in("Some file.xml", {'KeyAttr' => 'item'})
puts doc.to_yaml
Although this prints out the correct format, the dates are unsorted.
And some of the dates are in quotes while others are not quoted in the
yaml output. I also tried the follwoing:
puts doc.sort.to_yaml
This sorts the hash into multiple arrays which then adds extra dashes
to the yaml output, but the date order is sorted correctly.
So my question is how to sort the hash so that the dates are read in
the correct order when outputted to yaml, but also keep the hash format
and not convert it to an array to sort?
Thanks in advance
SA