
= amrita  XML

== 

amritaHTMLƱ͡XMLФƤѤ뤳ȤǤޤ

* amrita REXML ١ XML ѡäƤޤ

* amrita HTMLƱͤXHTMLʸ뤳ȤǤޤ

  XHTMLΥƥץ졼ȤѰդСXHTMLʸޤ

* amritaXMLʸƥץ졼ȤȤXMLʸ뤿˻Ѥ뤳ȤǤޤ

  amrita ˤ HTMLDTD(ι¤)˰¸ɤϤ鷺ޤ
  ޤOFFˤ뤳ȤưפˤǤޤ
  Ǥ顢XHTMLʳΰ̤XMLʸƥץ졼ȤȤƻѤ뤳ȤǤޤ

* amritaϥǥǡXMLɥȤ뤳ȤǤޤ

  REXMLRubyΤμAPI󶡤Ƥޤ
  ơREXMLɤߤXMLʸǥǡȤƻѤ뤳ȤưפˤǤޤ

* amx: XMLѤΤ⤦ҤȤĤΥ륷

  docs/Tour2 򻲾ȤƤ

---

== XHTMLʸ

=== ɤȽ

:

  :include: sample/tour/xhtml.rb

:

   <?xml version="1.0"?>                                           
   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
   <html xmlns="http://www.w3.org/1999/xhtml">                     
     <head>                                                        
       <title>xhtml sample</title>                                 
     </head>                                                       
     <body>                                                        
       <h1>SAMPLE1</h1>                                            
       <p>members of this HASH will be inserted here and title</p> 
       <hr />                                                      
     </body>                                                       
   </html>                                                         


=== 

Ūˡamrita  XHTMLƥץ졼ȤXHTMLʸHTML4.0ƥץ졼ȤHTML4.0ʸޤ
äơץޡɸ֥饦ǥХФŬ򤤤ˤɬפޤ
ϡǥʡ(ƥץ졼Ȥ񤯿)λŻˤʤޤ

ץޡ뤳Ȥ Template ֥ +asxml+ ե饰ꤹ뤳ȤǤ
줬 +true+ ꤵƤȡ
<tt><hr></tt> Τ褦ñȤΥ <tt><hr /></tt> Τ褦XMLηǽϤޤ

---

== XML ƥץ졼

=== ɤȽ

:

   data = {                                                                                                    
      :table1=>[                                                                                               
         { :name=>"Ruby In A Nutshell", :author=>"Yukihiro Matsumoto, David L. Reynolds", :isbn=>"0596002149" }
         { :name=>"Programming Ruby", :author=>"David Thomas, Andrew Hunt", :isbn=>"0201710897" },             
         { :name=>"The Ruby Way", :author=>"Hal Fulton", :isbn=>"0672320835" },                                
      ]                                                                                                        
   }                                                                                                           
                                                                                                               
   xml_tmpl = TemplateText.new <<END                                                                           
   <booklist>                                                                                                  
     <book id="table1">                                                                                        
        <title id="name" />                                                                                    
        <author id="author" />                                                                                 
        <isbn id="isbn" />                                                                                     
     </book>                                                                                                   
   </booklist>                                                                                                 
   END                                                                                                         
                                                                                                               
   xml_tmpl.xml = true # use REXML-based parser
   puts "------------XML output ----------------------"                                                        
   xml_tmpl.expand(STDOUT, data)                                                                               
                                                                                                               
:

   <booklist>
     <book>
       <title>Ruby In A Nutshell</title>
       <author>Yukihiro Matsumoto, David L. Reynolds</author>
       <isbn>0596002149</isbn>
     </book><book>
       <title>Programming Ruby</title>
       <author>David Thomas, Andrew Hunt</author>
       ..........

=== 

   xml_tmpl.xml = true # REXML١ΥѡѤ
   puts "------------XML output ----------------------"                                                        
   xml_tmpl.expand(STDOUT, data)                                                                               

amritaɬפޤǥƥץ졼Ȥɤޤ
ǽ +expand+ ƤФ +xml+ ե饰ꤵƤȡ
amrita REXML١ΥѡѤޤ

amritaǤϡҤȤĤΥǥǡʣΥƥץ졼ȤŬѤ뤳ȤǤޤ
äơΥɤXMLHTMLξϤ뤳ȤǤޤ
ܤ sample/tour/xml1.rb 򻲾ȤƤ


---

== XMLʸǥǡȤƻѤ

  XMLʸ(ǡ) + HTMLƥץ졼 ==> HTMLʸ

ĤޤꡢΥ륷ȤȤamritaѤˡǤ

=== code and output

code:

  :include: sample/tour/xml2.rb

output:

   <table border="1">                                                                      
     <tr>                                                                                  
     <th>title</th>                                                                        
     <th>author</th>                                                                       
     <th>ISBN</th>                                                                         
     </tr>                                                                                 
     <tr>                                                                                  
     <td>Ruby In A Nutshell</td>                                                           
     <td>Yukihiro Matsumoto<br>David L. Reynolds                                           
     <br>                                                                                  
     </td>                                                                                 
     <td><a href="http://www.amazon.com/exec/obidos/ASIN/0596002149">0596002149</a></td>   
     </tr>                                                                                 
     <tr>                                                                                  
     <td>Programming Ruby</td>                                                             
     <td>David Thomas<br>Andrew Hunt                                                       
     <br>                                                                                  
     </td>                                                                                 
     <td><a href="http://www.amazon.com/exec/obidos/ASIN/0201710897">0201710897</a></td>   
     </tr>                                                                                 
     <tr>                                                                                  
     <td>The Ruby Way</td>                                                                 
     <td>Hal Fulton<br>                                                                    
     </td>                                                                                 
     <td><a href="http://www.amazon.com/exec/obidos/ASIN/0672320835">0672320835</a></td>   
     </tr>                                                                                 
   </table>                                                                                


=== description

   table = doc.elements.to_a("booklist/book").collect do |book|                                  
     {
       :xxx=>.....
     }                                                                                           
   end                                                                                           

Υɤϡ<tt><book></tt>ǤޤHashޤ
<tt><book></tt>ǤREXML::Element饹Υ󥹥󥹤Ǥ
Ǥ顢REXMLAPIˤäơ̥Ρɤ°ͤФȤǤޤ


       :title=>book.elements['title'],

<tt>book.elements['title']</tt>ϡ<tt><book></tt> Ǥĺǽ <tt><title></tt> ǤǤ

       :authors=>book.elements.to_a('author').collect do |a|                                     
         { :name=>a }                                                                            
       end,                               

ܤˤϥȥϰĤޤ󤬡Ԥʣ礬ޤ
äơ(author) +to_a+ˤäArrayȤƽޤ
Ruby ɸ᥽åɤǤ롢+collect+ѤHashƤޤ

       :isbn=>e(:a, :href=>"http://www.amazon.com/exec/obidos/ASIN/#{book.attributes['isbn']}") {
         book.attributes['isbn']                                                                 
       }                                                                                         

Ǥϡޥؤľܥ󥯤ŽȤƤޤ
e(...) { ... } ϼΤ褦ʥޤ

    <a href="http://www.amazon.com/exec/obidos/ASIN/0596002149">0596002149</a>


Υǥ(amrita١XML륷)򤵤ȯŸ㤬
sample/tour/xml3.rbˤޤơ amx ȤǽȤƤޤȤƤޤ
ܺ٤ docs/Tour2 򻲾ȤƤ


---

== Ruby Υ֥ȤXMLιܤѴ

RubyΥ֥ȤXMLб褦Ȥȡ
°бСȲǤбСȻפޤ

Υץϡ<tt>ls -l</tt>Τ褦ʾXMLȤ󶡤Ǥ

=== ɤȽ

:

  :include: sample/tour/filelist.rb

:

  <file name="CVS" type="directory">
     <mode>drwxr-xr-x</mode>
     <times>
       <ctime>Tue Sep 03 11:07:10 JST 2002</ctime>
       <mtime>Tue Sep 03 11:07:10 JST 2002</mtime>
       <atime>Thu Sep 05 07:30:39 JST 2002</atime>
     </times>
     <unix_inf uid="1000" gid="1000" dev="770">
        <inode>652250</inode>
     </unix_inf>
  </file>
  <file name="precompile.rb" type="file">
     <size>2596</size>
     <mode>-rw-r--r--</mode>
     <times>
       <ctime>Mon Aug 26 09:12:11 JST 2002</ctime>
       <mtime>Mon Aug 26 09:12:11 JST 2002</mtime>
       <atime>Thu Sep 05 09:26:48 JST 2002</atime>
     </times>
     <unix_inf uid="1000" gid="1000" dev="770">
        <inode>310411</inode>
     </unix_inf>
  </file>
  <file name="amstest.ams" type="file">
  .....


=== 

    def entry(name)
      a(:name=>name, :type=>ftype) { self }
    end

Υ᥽åɤAttrArray֥Ȥ
°ͤꤷƤ鲼ǤʬȤŸޤ

    def size_or_nil
      size if ftype == "file"
    end

⤷ե뤬̾եǤʤȡ
Υ᥽åɤnil֤<tt><size></tt> ǤϺޤ


---

