Meteorのサンプル(HTMLの場合)

test_html.rb

#!bin ruby
# -* coding: UTF-8 -*-

require 'rubygems'
require 'meteor'

pf = Meteor::ParserFactory.new
pf.parser(Meteor::Parser::HTML,'test.html', 'UTF-8')
ps = pf.parser('test')

elm_hello = ps.element('id','hello')
elm_hello.attr('color','red')

elm_hello2 = ps.element('id','hello2')
elm_hello2.content('Hello,Tester')

elm_hello3 = ps.cxtag('hello3')
elm_hello3.content('Hello,Hello')

elm_text1 = ps.element('id','text1')
elm_text1.attr('value','めも')
elm_text1.attr('disabled','true')
#map = elm_text1.attr_map
#map.names.each { |item| 
#  puts item
#  puts map.fetch(item)
#}

elm_radio1 = ps.element('input','id','radio1','type','radio')
elm_radio1.attr('checked','true')

#elm_select1 = ps.element('select','id','select1')
elm_select1 = ps.element('select')
#elm_select1.attr('multiple','true')
elm_select1['multiple'] = true
##puts elm_select1.attr('multiple')
#puts elm_select1['multiple']

elm_option1 = ps.element('option','id','option1')
#elm_option1.attr('selected','true')
elm_option1['selected'] = true
##ps.remove_attr(elm_option1,'selected')
#elm_option1.remove_attr('selected')
##puts elm_option1.attr('selected')
#puts elm_option1['selected']
#puts elm_text1.attr('readonly')

#elm_select2 = ps.element('select','id','select2')
#elm_select2['multiple'] = 'true'
#elm_option2 = ps.element('option','id','option2')
#elm_ = ps.element(elm_option2)
#10.times { |i|
#  elm_.attr('value',i.to_s)
#  if i == 1 then
#    elm_.attr('selected','true')
#  else
#    #elm_.attr('selected','false')
#  end
#  elm_.content(i.to_s)
#  elm_.remove_attr('id')
#  elm_.flush
#}

elm_tr1 = ps.element('tr','id','loop')
elm_ = ps.element(elm_tr1)
elm_dt1_ = elm_.child('id','aa')
elm_dt2_ = elm_.child('id','bb')
elm_dt3_ = elm_.child('id','cc')
10.times { |i|
  elm_['loop'] = i.to_s
  elm_dt1 = elm_dt1_.clone
  elm_dt2 = elm_dt2_.clone
  elm_dt3 =  elm_dt3_.clone
  elm_dt1.content = i.to_s   
  elm_dt2.content = i.to_s  
  elm_dt3.content = i.to_s
  elm_.flush
}

ps.flush

puts ps.document

test.html

<html>
<head>
<title>HTMLテスト</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<font id="hello" color="#000000">Hello,World</font>
<font id="hello2">Hello,World</font>
<!-- @quark id="hello3" -->Hello,World<!-- /@quark -->
<form>
<input id="text1" type="text" >

<input id="radio1" type="radio">

<select>
    <option id="option1">オプション</option>
</select>

<select id="select2">
    <option id="option2">オプション</option>
</select>
</form>

<table>
    <tr id="loop">
        <td id="aa"></td><td id="bb"></td><td id="cc"></td>
    </tr>
</table>

</body>
</html>