I have a table called "users", which has three columns:
id, ref, name
I want to parse the following XML document using Nokogiri and list the matched and unmatched records by comparing the values in the "users" table records:
<?xml version="1.0" encoding="UTF-8"?>
<EXPORT>
<DETAIL>
<ID>150</ID>
<REF>188440</REF>
<USER>Bruce</USER>
</DETAIL>
<DETAIL>
<ID>1501003</ID>
<REF>1884402</REF>
<USER>Alice</USER>
</DETAIL>
</EXPORT>
For example:
Users.where(id: 1501003).name
Users.where(ref: 188440).name
Find the name by comparing the id and ref.
Note: if id does not match, then compare with ref. If id matches then ignore ref.
I tried:
doc = Nokogiri::XML(File.open(self.filename))
exp = "//EXPORT/DETAIL"
NODES = doc.xpath(exp)
nodes.each do |node|
unless node.text.nil?
User.where(id: node.text).first.name
end