I'm using Ruby, Norkigiri and Nori. I would like some thoughts about how I should go about parsing this XML file.
In this schema, an entity can include multiple contacts.
I need to return a hash of the following:
- :id
- :first_name
- :last_name
- :preferred_email
- :manager
I thought about using xpath to try return the preferred email contact.
entities = doc.xpath("/entity_list/entity").each do |entity|
puts entity.xpath("contact_list/contact[contains(type,'Email') and contains(preferred, '1')]")
end
<entity>
<id>21925</id>
<last_name>Smith</last_name>
<first_name>John</first_name>
<preferred_name>Johnny</preferred_name>
<manager>Timmy</manager>
<dob>1970-01-01</dob>
<type>individual</type>
<contact_list>
<contact>
<type>Mobile Phone</type>
<preferred>0</preferred>
<value>563478653478</value>
</contact>
<contact>
<type>Pager</type>
<preferred>0</preferred>
<value>7354635345</value>
</contact>
<contact>
<notes>None</notes>
<type>Home Email</type>
<preferred>1</preferred>
<value>[email protected]</value>
<comments>None</comments>
</contact>
<contact>
<notes>None</notes>
<type>Work Email</type>
<preferred>0</preferred>
<value>[email protected]</value>
<comments>None</comments>
</contact>
<contact>
<type>Home Phone</type>
<preferred>1</preferred>
<value>56537646365</value>
</contact>
</contact_list>
</entity>
What would be the best way to approach this problem?
Thanks