0
我使用引入nokogiri解析這個XML:引入nokogiri和Rails - 小問題
<?xml version="1.0" encoding="utf-8"?>
<GetPropertiesResponse>
<Properties>
<Property>
<Id>19</Id>
<Name>Property 1</Name>
<Breakfast></Breakfast>
<Currency>GBP</Currency>
</Property>
<Property>
<Id>13</Id>
<Name>Property 2</Name>
<Breakfast>IN</Breakfast>
<Currency>EUR</Currency>
</Property>
<Property>
<Id>15</Id>
<Name>Property 3</Name>
<Breakfast>EX</Breakfast>
<Currency>GBP</Currency>
</Property>
</Properties>
</GetPropertiesResponse>
這樣的:
...
doc = Nokogiri::XML(response.body)
@property = doc.xpath("//Property")
,然後在我看來,我顯示每個屬性的名稱,像這樣:
<%= @property.each do |item| %>
<%= item.xpath("Name").text %><br>
<% end %>
但我始終輸出對最終神祕0
,我不知道爲什麼?我的輸出是這樣的:
Property 1
Property 2
Property 3
0
你是明星!歡呼聲 - 當它讓我時會打勾 – tommyd456