I am using the UPS API to validate locations. I receive the XML response from UPS then try to parse out the information I need. UPS can send back one to three <AddressLine> elements per address, depending on the address.
If an address has two or more AddressLines, I need to pull out the first two. If an address has only one AddressLine, I need to pull that one line.
How can I pull out address and address2?
<AddressKeyFormat>
<AddressLine>655 MANSELL RD</AddressLine>
<AddressLine>Apartment #2</AddressLine>
</AddressKeyFormat>
The code :
xml.xpath('//AddressKeyFormat').each do |node|
#pull out address, and address2
end
Assuming that
xmlis a Nokogiri XML document (e.g.xml = Nokogiri::XML(xmlString)) you can do an XPath search for//AddressLineand the result will be all of those nodes: