xmlsimple: prevent folding multiple elements into array?

Discussion in 'Ruby' started by slothbear, Jul 17, 2007.

  1. slothbear

    slothbear Guest

    I have some xml that represents a somewhat weirdly formed hash.
    XmlSimple is eating some of my structure.

    INPUT:
    <kern>
    <map>
    <key>
    state
    </key>
    <string>
    open
    </string>
    <key>
    rate
    </key>
    <time>
    daily
    </time>
    <key>
    duration
    </key>
    <time>
    monthly
    </time>
    </map>
    </kern>

    XmlSimple.xml_in(xml, {'ForceArray'=>false})

    OUTPUT:
    {"map"=> {
    "time"=>["daily", "monthly"],
    "key"=>["state", "rate", "duration"],
    "string"=>"open"
    }
    }

    With the arrays folded that way, there's no way for me to tell that
    the value of "state" is "open". I don't really care about the
    "datatypes". I'm aiming at a single level hash something like this:

    DESIRED:
    {"map"=> {
    "state" => "open,
    "rate" => "daily",
    "duration" => "monthly"
    }
    }

    I can't really change the odd incoming XML, but I'm happy to process
    any Ruby data structure that hasn't lost some of my order/structure.
    All of the options around folding appear to affect only attributes,
    but I have only elements.
    slothbear, Jul 17, 2007
    #1
    1. Advertising

  2. Man, wish I could help you there. The problem is that the only languages
    that I have been able to work with XML in are ActionScript and Java...
    and Ruby really doesn't look like either, not to mention I can't even
    seem to find some decent tutorials that explain it...

    Oh well, sorry for taking up space on this thread. But perchance, you
    may want to investigate the REXML library that comes with Ruby. It's
    just an alternative to XMLSimple.


    --
    Posted via http://www.ruby-forum.com/.
    Weston Mr. campbell, Jul 17, 2007
    #2
    1. Advertising

  3. slothbear

    slothbear Guest

    Thanks for the thoughts! I figured I would have to move to REXML
    eventually, and I guess it's time. thanks again.
    slothbear, Jul 20, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hborda
    Replies:
    1
    Views:
    79
    David Vallner
    Nov 5, 2006
  2. Matt Valblade

    XMLsimple & probem

    Matt Valblade, Oct 11, 2007, in forum: Ruby
    Replies:
    4
    Views:
    95
    Matt Valblade
    Oct 11, 2007
  3. Srijayanth Sridhar
    Replies:
    0
    Views:
    80
    Srijayanth Sridhar
    Jun 13, 2008
  4. Maui Guide
    Replies:
    1
    Views:
    104
    Robert Klemme
    Apr 17, 2009
  5. dare ruby

    XmlSimple not working

    dare ruby, May 20, 2010, in forum: Ruby
    Replies:
    0
    Views:
    90
    dare ruby
    May 20, 2010
Loading...

Share This Page