File: XML_ja

package info (click to toggle)
ruby-amrita 1.0.2-10
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 1,940 kB
  • sloc: ruby: 9,159; xml: 978; makefile: 78
file content (270 lines) | stat: -rw-r--r-- 11,646 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270

= 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> ǤϺޤ


---