Reading XML with my own ten-foot poll.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

XML Hate Build Status Coverage Status

Reading XML with my own ten-foot poll.

xml_hate is a small gem that describes my feelings for XML imports. I've written a billion of them, yet each time I start another I feel like I'm writing Assembler. Shouldn't it be easier? Shouldn't the code look nicer? Shouldn't this be more fun?

I've also noticed a number of things that I always tend to do. I always convert the XML to objects, I parse through the hierarchy to find child objects, I put in defensive checks for data that might-or-might-not exist, etc.

This gem is where I'm going to put these conventions and processes of mine. My goal is to take a XML document and immediately get it in the form that I need to use it.


    <employee lastname="Galt">
      <address>123 W St</address>
      <address>456 S Blvd</address>
    <employee lastname="Roark" firstname="Howard">
      <address>789 S</address>
    <employee lastname="Rearden" />
document = # 3, note pluralization happened automatically

john_galt =[0]

# note how I treat the single-value element and attribute the same
john_galt.lastname # Galt
john_galt.firstname # John

john_galt.addresses.count # 2, notice pluralization again

howard_roark =[1]

howard_roark.firstname # Howard
howard_roark.lastname # Roark
howard_roark.addresses.count # 1
howard_roark.address # 789 S

rearden =[2]
rearden.lastname # Rearden
rearden.firstname # "", defaults to empty string if the value cannot be found
rearden.whatever_i_want # "", see above
rearden.addresses.count # 0, returns [] by assuming you want the plural version