0
我有以下XML文檔,並且想使用happymapper將xml轉換爲對象。HappyMapper命名空間前綴錯誤
<objects>
<item>
<title>book1</title>
<link>http://asdf.com</link>
<pubDate>march 1 2009</pubDate>
<description>testtesttest</description>
<media:thumbnail url='http://url.com' />
</item>
<item>
<title>book2</title>
<link>http://dffdfdf.com</link>
<pubDate>march 3 2009</pubDate>
<description>testtesttest</description>
<media:thumbnail url='http://url.com' />
</item>
</objects>
#HappyMapper object
class Item
include HappyMapper
namespace 'http://search.yahoo.com/mrss/'
element :title, String
element :link, String
element :pubDate, String
element :description, String
element :media_thumbnail, String, :tag=>'media:thumbnail', :attributes=>{:url=>String}
end
items=Item.parse(xml_document)
items.each do |i|
puts i.title
puts i.media_thumbnail.url
end
錯誤:縮略圖上的名稱空間前綴媒體未在以下位置定義:11。
錯誤:縮略圖上的命名空間前綴媒體未在22處定義。
謝謝我需要將ns添加到我的xml文檔。但它不需要將ns添加到happymapper對象。 – Dejan 2011-02-16 16:15:23