這篇不知道該分類到XML還是Ruby教學.. 不過因為是講Ruby搭配REXML.. 應該是Ruby教學吧??
由於王宗松老師的案子,讓我興起了用Ruby寫個XML公佈欄的念頭
用Ruby + REXML可以很輕鬆的Parsing XML!搭配XML Builder則可以非常容易的寫XML!
OK,閒話休提.. 目前檔案應該是這樣的...

XML_BB/
  ├ functions/
  │  ├ include.rb
  │  └ funcs.rb
  ├ list_news.rb
  └ news.rb

檔案目前是只有這些拉!
其中include.rb裡面是引入檔案:
  $KCODE = "UTF-8"
  require 'rexml/document'
  require 'jcode'
  include REXML


funcs.rb裡面:
  def load_file(file)
    return Document.new(File.new(file))
  end
 
  def set_path(path)
    return path
  end

  def get_elements_num(doc, path)
    return XPath.match(doc, path).size
  end

  def show_author(nme_hash, news, path, num)
    print nme_hash["author"] + ":"
    puts news.elements["#{path}item[#{num}]/author"].attributes["name"]
    puts "====="
  end

暫時寫到這邊,等程式完成之後再PO其他檔案的原始碼
這個版本暫時不支援RSS,未來會推出支援RSS 2.0標準的XMLBB

arrow
arrow
    全站熱搜

    hechian 發表在 痞客邦 留言(0) 人氣()