2012-10-24 146 views
0

我希望xmlns='http://www.w3.org/2005/Atom'出現在Feed和條目標記中。 但是不知道爲什麼我的條目標籤丟失xmlns='http://www.w3.org/2005/Atom'使用Nokogiri構建XML名稱空間

在這裏,我想實現

<?xml version='1.0' encoding='UTF-8'?> 
<feed xmlns='http://www.w3.org/2005/Atom' xmlns:batch='http://schemas.google.com/gdata/batch'> 
    <entry xmlns='http://www.w3.org/2005/Atom' xmlns:app='http://www.w3.org/2007/app' xmlns:sc='http://schemas.google.com/structuredcontent/2009' xmlns:scp='http://schemas.google.com/structuredcontent/2009/products'> 

這裏是我的代碼

builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml| 
    xml.feed('xmlns' => 'http://www.w3.org/2005/Atom', 
      'xmlns:batch' => 'http://schemas.google.com/gdata/batch') do 
       xml.entry('xmlns' => 'http://www.w3.org/2005/Atom', 
         'xmlns:app' => 'http://www.w3.org/2007/app', 
         'xmlns:sc' => 'http://schemas.google.com/structuredcontent/2009', 
         'xmlns:scp' => 'http://schemas.google.com/structuredcontent/2009/products') 
      end 
end 
+0

這很奇怪,在我的機器上沒有錯。 – halfelf

+0

@halfelf他缺少'entry'中的'xmlns'標記。 – oldergod

回答

0

在XML中,xmlns標籤是繼承的結果由子節點。因爲entryfeed的子項,並且它們與xmlns的值相同,所以Nokogiri可能會優化子節點上的條目。