Ruby - Nokogiri - Need to put node.value to an array
        Posted  
        
            by 
                r3nrut
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by r3nrut
        
        
        
        Published on 2011-01-12T20:01:11Z
        Indexed on 
            2011/01/12
            21:53 UTC
        
        
        Read the original article
        Hit count: 249
        
What I'm trying to do is read the value for all the nodes in this XML and put them into an array. This should be simple but for some reason it's driving me nuts.
XML
<ArrayOfAddress>
<Address>
<AddressId>297424fe-cfff-4ee1-8faa-162971d2645f</AddressId>
<FirstName>George</FirstName>
<LastName>Washington</LastName>
<Address1>123 Main St</Address1>
<Address2>Apt #611</Address2>
<City>New York</City>
<State>NY</State>
<PostalCode>10110</PostalCode>
<CountryCode>US</CountryCode>
<EmailAddress>[email protected]</EmailAddress>
<PhoneNumber>5555551234</PhoneNumber>
<AddressType>CustomerAddress</AddressType>
</Address>
</ArrayOfAddress>
Code
class MassageRepsone
def parse_resp
    @@get_address.url_builder #URL passed through HTTPClient - @@resp is the xml above
      doc = Nokogiri::XML::Reader(@@resp)
      @@values = doc.each do |node|
         node.value
    end
end
    @@get_address.parse_resp
    obj = [@@values] 
    Array(obj)
    p obj
end
The code snippet from above returns the following:
297424fe-cfff-4ee1-8faa-162971d2645f
George
Washington
123 Main St
Apt #622
New York
NY
10110
US
test.test.com
5555551234
CustomerAddress
I tried putting @@values to a string and applying chomp but that just prints the newlines as nil and puts quotes around the values. Not sure what the next step is or if I need to approach this differently with Nokogiri.
© Stack Overflow or respective owner