roxml 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE.txt +9 -0
- data/doc/classes/ROXML.html +352 -0
- data/doc/classes/ROXML.src/M000003.html +19 -0
- data/doc/classes/ROXML.src/M000004.html +25 -0
- data/doc/classes/ROXML.src/M000005.html +22 -0
- data/doc/classes/ROXML/ROXML_Class.html +422 -0
- data/doc/classes/ROXML/ROXML_Class.src/M000006.html +27 -0
- data/doc/classes/ROXML/ROXML_Class.src/M000007.html +18 -0
- data/doc/classes/ROXML/ROXML_Class.src/M000008.html +19 -0
- data/doc/classes/ROXML/ROXML_Class.src/M000009.html +24 -0
- data/doc/classes/ROXML/ROXML_Class.src/M000010.html +24 -0
- data/doc/classes/ROXML/ROXML_Class.src/M000011.html +18 -0
- data/doc/classes/ROXML/ROXML_Class.src/M000012.html +18 -0
- data/doc/classes/ROXML/XMLAttributeRef.html +175 -0
- data/doc/classes/ROXML/XMLAttributeRef.src/M000015.html +19 -0
- data/doc/classes/ROXML/XMLAttributeRef.src/M000016.html +19 -0
- data/doc/classes/ROXML/XMLObjectRef.html +175 -0
- data/doc/classes/ROXML/XMLObjectRef.src/M000013.html +26 -0
- data/doc/classes/ROXML/XMLObjectRef.src/M000014.html +32 -0
- data/doc/classes/ROXML/XMLRef.html +212 -0
- data/doc/classes/ROXML/XMLRef.src/M000017.html +21 -0
- data/doc/classes/ROXML/XMLRef.src/M000018.html +18 -0
- data/doc/classes/ROXML/XMLRef.src/M000019.html +18 -0
- data/doc/classes/ROXML/XMLTextRef.html +193 -0
- data/doc/classes/ROXML/XMLTextRef.src/M000020.html +26 -0
- data/doc/classes/ROXML/XMLTextRef.src/M000021.html +33 -0
- data/doc/classes/String.html +165 -0
- data/doc/classes/String.src/M000001.html +23 -0
- data/doc/classes/String.src/M000002.html +23 -0
- data/doc/created.rid +1 -0
- data/doc/files/lib/roxml_rb.html +234 -0
- data/doc/fr_class_index.html +33 -0
- data/doc/fr_file_index.html +27 -0
- data/doc/fr_method_index.html +47 -0
- data/doc/index.html +24 -0
- data/doc/rdoc-style.css +208 -0
- data/lib/roxml.rb +507 -0
- data/test/fixture_helper.rb +5 -0
- data/test/fixtures/book_malformed.xml +5 -0
- data/test/fixtures/book_pair.xml +8 -0
- data/test/fixtures/book_valid.xml +5 -0
- data/test/fixtures/book_with_contributions.xml +9 -0
- data/test/fixtures/book_with_contributors.xml +7 -0
- data/test/fixtures/book_with_publisher.xml +7 -0
- data/test/fixtures/library.xml +30 -0
- data/test/mocks/mocks.rb +59 -0
- data/test/test_roxml.rb +90 -0
- metadata +104 -0
data/MIT-LICENSE.txt
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2006 Zak Mandhro and Anders Engstrom
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
6
|
+
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
8
|
+
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,352 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
7
|
+
<head>
|
8
|
+
<title>Module: ROXML</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
+
<link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
|
12
|
+
<script type="text/javascript">
|
13
|
+
// <![CDATA[
|
14
|
+
|
15
|
+
function popupCode( url ) {
|
16
|
+
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
17
|
+
}
|
18
|
+
|
19
|
+
function toggleCode( id ) {
|
20
|
+
if ( document.getElementById )
|
21
|
+
elem = document.getElementById( id );
|
22
|
+
else if ( document.all )
|
23
|
+
elem = eval( "document.all." + id );
|
24
|
+
else
|
25
|
+
return false;
|
26
|
+
|
27
|
+
elemStyle = elem.style;
|
28
|
+
|
29
|
+
if ( elemStyle.display != "block" ) {
|
30
|
+
elemStyle.display = "block"
|
31
|
+
} else {
|
32
|
+
elemStyle.display = "none"
|
33
|
+
}
|
34
|
+
|
35
|
+
return true;
|
36
|
+
}
|
37
|
+
|
38
|
+
// Make codeblocks hidden by default
|
39
|
+
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
40
|
+
|
41
|
+
// ]]>
|
42
|
+
</script>
|
43
|
+
|
44
|
+
</head>
|
45
|
+
<body>
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
<div id="classHeader">
|
50
|
+
<table class="header-table">
|
51
|
+
<tr class="top-aligned-row">
|
52
|
+
<td><strong>Module</strong></td>
|
53
|
+
<td class="class-name-in-header">ROXML</td>
|
54
|
+
</tr>
|
55
|
+
<tr class="top-aligned-row">
|
56
|
+
<td><strong>In:</strong></td>
|
57
|
+
<td>
|
58
|
+
<a href="../files/lib/roxml_rb.html">
|
59
|
+
lib/roxml.rb
|
60
|
+
</a>
|
61
|
+
<br />
|
62
|
+
</td>
|
63
|
+
</tr>
|
64
|
+
|
65
|
+
</table>
|
66
|
+
</div>
|
67
|
+
<!-- banner header -->
|
68
|
+
|
69
|
+
<div id="bodyContent">
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
<div id="contextContent">
|
74
|
+
|
75
|
+
<div id="description">
|
76
|
+
<p>
|
77
|
+
<a href="ROXML.html">ROXML</a> Ruby Object to XML mapping library. For more
|
78
|
+
information visit <a
|
79
|
+
href="http://roxml.rubyforge.org">roxml.rubyforge.org</a>
|
80
|
+
</p>
|
81
|
+
<p>
|
82
|
+
Copyright © 2004-2006 Zak Mandhro and Anders Engstrom
|
83
|
+
</p>
|
84
|
+
<p>
|
85
|
+
Permission is hereby granted, free of charge, to any person obtaining a
|
86
|
+
copy of this software and associated documentation files (the
|
87
|
+
"Software"), to deal in the Software without restriction,
|
88
|
+
including without limitation the rights to use, copy, modify, merge,
|
89
|
+
publish, distribute, sublicense, and/or sell copies of the Software, and to
|
90
|
+
permit persons to whom the Software is furnished to do so, subject to the
|
91
|
+
following conditions:
|
92
|
+
</p>
|
93
|
+
<p>
|
94
|
+
The above copyright notice and this permission notice shall be included in
|
95
|
+
all copies or substantial portions of the Software.
|
96
|
+
</p>
|
97
|
+
<p>
|
98
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
99
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
100
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
101
|
+
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
102
|
+
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
103
|
+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
104
|
+
USE OR OTHER DEALINGS IN THE SOFTWARE.
|
105
|
+
</p>
|
106
|
+
<h1>Quick Start Guide</h1>
|
107
|
+
<p>
|
108
|
+
This is a short usage example. See <a
|
109
|
+
href="ROXML/ROXML_Class.html">ROXML::ROXML_Class</a> and packaged test
|
110
|
+
cases for more information.
|
111
|
+
</p>
|
112
|
+
<p>
|
113
|
+
Consider an XML document representing a Library containing a number of
|
114
|
+
Books. You can map this structure to Ruby classes that provide addition
|
115
|
+
useful behavior. With <a href="ROXML.html">ROXML</a>, you can annotate the
|
116
|
+
Ruby classes as follows:
|
117
|
+
</p>
|
118
|
+
<pre>
|
119
|
+
class Book
|
120
|
+
include ROXML
|
121
|
+
|
122
|
+
xml_attribute :isbn, "ISBN"
|
123
|
+
xml_text :title
|
124
|
+
xml_text :description, nil, ROXML::TAG_CDATA
|
125
|
+
xml_text :author
|
126
|
+
end
|
127
|
+
|
128
|
+
class Library
|
129
|
+
include ROXML
|
130
|
+
|
131
|
+
xml_text :name, "NAME", ROXML::TAG_CDATA
|
132
|
+
xml_object :books, Book, ROXML::TAG_ARRAY, "books"
|
133
|
+
end
|
134
|
+
</pre>
|
135
|
+
<p>
|
136
|
+
To create a library and put a number of books in it we could run the
|
137
|
+
following code:
|
138
|
+
</p>
|
139
|
+
<pre>
|
140
|
+
book = Book.new()
|
141
|
+
book.isbn = "0201710897"
|
142
|
+
book.title = "The PickAxe"
|
143
|
+
book.description = "Best Ruby book out there!"
|
144
|
+
book.author = "David Thomas, Andrew Hunt, Dave Thomas"
|
145
|
+
|
146
|
+
lib = Library.new()
|
147
|
+
lib.name = "Favorite Books"
|
148
|
+
lib << book
|
149
|
+
</pre>
|
150
|
+
<p>
|
151
|
+
To save this information to an XML file:
|
152
|
+
</p>
|
153
|
+
<pre>
|
154
|
+
File.open("library.xml", "w") do |f|
|
155
|
+
lib.to_xml.write(f, 0)
|
156
|
+
end
|
157
|
+
</pre>
|
158
|
+
<p>
|
159
|
+
To later populate the library object from the XML file:
|
160
|
+
</p>
|
161
|
+
<pre>
|
162
|
+
lib = Library.parse(File.read("library.xml"))
|
163
|
+
</pre>
|
164
|
+
<p>
|
165
|
+
Similarly, to do a one-to-one mapping between XML objects, such as book and
|
166
|
+
publisher, you would use the <b>xml_object</b> annotation. For example:
|
167
|
+
</p>
|
168
|
+
<pre>
|
169
|
+
<book isbn="0974514055">
|
170
|
+
<title>Programming Ruby - 2nd Edition</title>
|
171
|
+
<description>Second edition of the great book.</description>
|
172
|
+
<publisher>
|
173
|
+
<name>Pragmatic Bookshelf</name>
|
174
|
+
</publisher>
|
175
|
+
</book>
|
176
|
+
</pre>
|
177
|
+
<p>
|
178
|
+
can be mapped using the following code:
|
179
|
+
</p>
|
180
|
+
<pre>
|
181
|
+
class BookWithPublisher
|
182
|
+
include ROXML
|
183
|
+
|
184
|
+
xml_name :book
|
185
|
+
xml_object :publisher, Publisher
|
186
|
+
end
|
187
|
+
</pre>
|
188
|
+
<p>
|
189
|
+
Note: In the above example, <em>xml_name</em> annotation tells <a
|
190
|
+
href="ROXML.html">ROXML</a> to set the element name to "book" for
|
191
|
+
mapping to XML. The default is XML element name is the class name in
|
192
|
+
lowercase; "bookwithpublisher" in this case.
|
193
|
+
</p>
|
194
|
+
<p>
|
195
|
+
For more information on available annotations, see <a
|
196
|
+
href="ROXML/ROXML_Class.html">ROXML::ROXML_Class</a>
|
197
|
+
</p>
|
198
|
+
|
199
|
+
</div>
|
200
|
+
|
201
|
+
|
202
|
+
</div>
|
203
|
+
|
204
|
+
<div id="method-list">
|
205
|
+
<h3 class="section-bar">Methods</h3>
|
206
|
+
|
207
|
+
<div class="name-list">
|
208
|
+
<a href="#M000003">included</a>
|
209
|
+
<a href="#M000005">method_missing</a>
|
210
|
+
<a href="#M000004">to_xml</a>
|
211
|
+
</div>
|
212
|
+
</div>
|
213
|
+
|
214
|
+
</div>
|
215
|
+
|
216
|
+
|
217
|
+
<!-- if includes -->
|
218
|
+
|
219
|
+
<div id="section">
|
220
|
+
|
221
|
+
<div id="class-list">
|
222
|
+
<h3 class="section-bar">Classes and Modules</h3>
|
223
|
+
|
224
|
+
Module <a href="ROXML/ROXML_Class.html" class="link">ROXML::ROXML_Class</a><br />
|
225
|
+
Class <a href="ROXML/XMLAttributeRef.html" class="link">ROXML::XMLAttributeRef</a><br />
|
226
|
+
Class <a href="ROXML/XMLObjectRef.html" class="link">ROXML::XMLObjectRef</a><br />
|
227
|
+
Class <a href="ROXML/XMLRef.html" class="link">ROXML::XMLRef</a><br />
|
228
|
+
Class <a href="ROXML/XMLTextRef.html" class="link">ROXML::XMLTextRef</a><br />
|
229
|
+
|
230
|
+
</div>
|
231
|
+
|
232
|
+
<div id="constants-list">
|
233
|
+
<h3 class="section-bar">Constants</h3>
|
234
|
+
|
235
|
+
<div class="name-list">
|
236
|
+
<table summary="Constants">
|
237
|
+
<tr class="top-aligned-row context-row">
|
238
|
+
<td class="context-item-name">TAG_READONLY</td>
|
239
|
+
<td>=</td>
|
240
|
+
<td class="context-item-value">1</td>
|
241
|
+
<td width="3em"> </td>
|
242
|
+
<td class="context-item-desc">
|
243
|
+
Option that may be used to declare that a variable accessor should be
|
244
|
+
read-only (no "accessor=(val)" is generated).
|
245
|
+
|
246
|
+
</td>
|
247
|
+
</tr>
|
248
|
+
<tr class="top-aligned-row context-row">
|
249
|
+
<td class="context-item-name">TAG_CDATA</td>
|
250
|
+
<td>=</td>
|
251
|
+
<td class="context-item-value">2</td>
|
252
|
+
<td width="3em"> </td>
|
253
|
+
<td class="context-item-desc">
|
254
|
+
Option that declares that an XML text element should be wrapped in a CDATA
|
255
|
+
section.
|
256
|
+
|
257
|
+
</td>
|
258
|
+
</tr>
|
259
|
+
<tr class="top-aligned-row context-row">
|
260
|
+
<td class="context-item-name">TAG_ARRAY</td>
|
261
|
+
<td>=</td>
|
262
|
+
<td class="context-item-value">4</td>
|
263
|
+
<td width="3em"> </td>
|
264
|
+
<td class="context-item-desc">
|
265
|
+
Option that declares an accessor as an array (referencing "many"
|
266
|
+
items).
|
267
|
+
|
268
|
+
</td>
|
269
|
+
</tr>
|
270
|
+
</table>
|
271
|
+
</div>
|
272
|
+
</div>
|
273
|
+
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
<!-- if method_list -->
|
280
|
+
<div id="methods">
|
281
|
+
<h3 class="section-bar">Public Class methods</h3>
|
282
|
+
|
283
|
+
<div id="method-M000003" class="method-detail">
|
284
|
+
<a name="M000003"></a>
|
285
|
+
|
286
|
+
<div class="method-heading">
|
287
|
+
<a href="ROXML.src/M000003.html" target="Code" class="method-signature"
|
288
|
+
onclick="popupCode('ROXML.src/M000003.html');return false;">
|
289
|
+
<span class="method-name">included</span><span class="method-args">(klass)</span>
|
290
|
+
</a>
|
291
|
+
</div>
|
292
|
+
|
293
|
+
<div class="method-description">
|
294
|
+
<p>
|
295
|
+
Extends the klass with the <a href="ROXML/ROXML_Class.html">ROXML_Class</a>
|
296
|
+
module methods.
|
297
|
+
</p>
|
298
|
+
</div>
|
299
|
+
</div>
|
300
|
+
|
301
|
+
<h3 class="section-bar">Public Instance methods</h3>
|
302
|
+
|
303
|
+
<div id="method-M000005" class="method-detail">
|
304
|
+
<a name="M000005"></a>
|
305
|
+
|
306
|
+
<div class="method-heading">
|
307
|
+
<a href="ROXML.src/M000005.html" target="Code" class="method-signature"
|
308
|
+
onclick="popupCode('ROXML.src/M000005.html');return false;">
|
309
|
+
<span class="method-name">method_missing</span><span class="method-args">(name, *args)</span>
|
310
|
+
</a>
|
311
|
+
</div>
|
312
|
+
|
313
|
+
<div class="method-description">
|
314
|
+
<p>
|
315
|
+
To make it easier to reference the class’s attributes all method
|
316
|
+
calls to the instance that doesn’t match an instance method are
|
317
|
+
forwarded to the class’s singleton instance. Only methods starting
|
318
|
+
with ‘tag_’ are delegated.
|
319
|
+
</p>
|
320
|
+
</div>
|
321
|
+
</div>
|
322
|
+
|
323
|
+
<div id="method-M000004" class="method-detail">
|
324
|
+
<a name="M000004"></a>
|
325
|
+
|
326
|
+
<div class="method-heading">
|
327
|
+
<a href="ROXML.src/M000004.html" target="Code" class="method-signature"
|
328
|
+
onclick="popupCode('ROXML.src/M000004.html');return false;">
|
329
|
+
<span class="method-name">to_xml</span><span class="method-args">()</span>
|
330
|
+
</a>
|
331
|
+
</div>
|
332
|
+
|
333
|
+
<div class="method-description">
|
334
|
+
<p>
|
335
|
+
Returns an REXML::Element representing this object.
|
336
|
+
</p>
|
337
|
+
</div>
|
338
|
+
</div>
|
339
|
+
|
340
|
+
|
341
|
+
</div>
|
342
|
+
|
343
|
+
|
344
|
+
</div>
|
345
|
+
|
346
|
+
|
347
|
+
<div id="validator-badges">
|
348
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
349
|
+
</div>
|
350
|
+
|
351
|
+
</body>
|
352
|
+
</html>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html>
|
7
|
+
<head>
|
8
|
+
<title>included (ROXML)</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
11
|
+
</head>
|
12
|
+
<body class="standalone-code">
|
13
|
+
<pre><span class="ruby-comment cmt"># File lib/roxml.rb, line 443</span>
|
14
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">included</span>(<span class="ruby-identifier">klass</span>)
|
15
|
+
<span class="ruby-keyword kw">super</span>
|
16
|
+
<span class="ruby-identifier">klass</span>.<span class="ruby-identifier">__send__</span>(<span class="ruby-identifier">:extend</span>, <span class="ruby-constant">ROXML_Class</span>)
|
17
|
+
<span class="ruby-keyword kw">end</span></pre>
|
18
|
+
</body>
|
19
|
+
</html>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html>
|
7
|
+
<head>
|
8
|
+
<title>to_xml (ROXML)</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
11
|
+
</head>
|
12
|
+
<body class="standalone-code">
|
13
|
+
<pre><span class="ruby-comment cmt"># File lib/roxml.rb, line 452</span>
|
14
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_xml</span>
|
15
|
+
<span class="ruby-identifier">root</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Element</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">tag_name</span>)
|
16
|
+
<span class="ruby-identifier">tag_refs</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">ref</span><span class="ruby-operator">|</span>
|
17
|
+
<span class="ruby-identifier">v</span> = <span class="ruby-identifier">__send__</span>(<span class="ruby-identifier">ref</span>.<span class="ruby-identifier">accessor</span>)
|
18
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">v</span>
|
19
|
+
<span class="ruby-identifier">root</span> = <span class="ruby-identifier">ref</span>.<span class="ruby-identifier">update_xml</span>(<span class="ruby-identifier">root</span>, <span class="ruby-identifier">v</span>)
|
20
|
+
<span class="ruby-keyword kw">end</span>
|
21
|
+
<span class="ruby-keyword kw">end</span>
|
22
|
+
<span class="ruby-identifier">root</span>
|
23
|
+
<span class="ruby-keyword kw">end</span></pre>
|
24
|
+
</body>
|
25
|
+
</html>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html>
|
7
|
+
<head>
|
8
|
+
<title>method_missing (ROXML)</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
11
|
+
</head>
|
12
|
+
<body class="standalone-code">
|
13
|
+
<pre><span class="ruby-comment cmt"># File lib/roxml.rb, line 468</span>
|
14
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">method_missing</span>(<span class="ruby-identifier">name</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
|
15
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">name</span>.<span class="ruby-identifier">id2name</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/^tag_/</span>
|
16
|
+
<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">__send__</span>(<span class="ruby-identifier">name</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
|
17
|
+
<span class="ruby-keyword kw">else</span>
|
18
|
+
<span class="ruby-keyword kw">super</span>
|
19
|
+
<span class="ruby-keyword kw">end</span>
|
20
|
+
<span class="ruby-keyword kw">end</span></pre>
|
21
|
+
</body>
|
22
|
+
</html>
|
@@ -0,0 +1,422 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
7
|
+
<head>
|
8
|
+
<title>Module: ROXML::ROXML_Class</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
+
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
12
|
+
<script type="text/javascript">
|
13
|
+
// <![CDATA[
|
14
|
+
|
15
|
+
function popupCode( url ) {
|
16
|
+
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
17
|
+
}
|
18
|
+
|
19
|
+
function toggleCode( id ) {
|
20
|
+
if ( document.getElementById )
|
21
|
+
elem = document.getElementById( id );
|
22
|
+
else if ( document.all )
|
23
|
+
elem = eval( "document.all." + id );
|
24
|
+
else
|
25
|
+
return false;
|
26
|
+
|
27
|
+
elemStyle = elem.style;
|
28
|
+
|
29
|
+
if ( elemStyle.display != "block" ) {
|
30
|
+
elemStyle.display = "block"
|
31
|
+
} else {
|
32
|
+
elemStyle.display = "none"
|
33
|
+
}
|
34
|
+
|
35
|
+
return true;
|
36
|
+
}
|
37
|
+
|
38
|
+
// Make codeblocks hidden by default
|
39
|
+
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
40
|
+
|
41
|
+
// ]]>
|
42
|
+
</script>
|
43
|
+
|
44
|
+
</head>
|
45
|
+
<body>
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
<div id="classHeader">
|
50
|
+
<table class="header-table">
|
51
|
+
<tr class="top-aligned-row">
|
52
|
+
<td><strong>Module</strong></td>
|
53
|
+
<td class="class-name-in-header">ROXML::ROXML_Class</td>
|
54
|
+
</tr>
|
55
|
+
<tr class="top-aligned-row">
|
56
|
+
<td><strong>In:</strong></td>
|
57
|
+
<td>
|
58
|
+
<a href="../../files/lib/roxml_rb.html">
|
59
|
+
lib/roxml.rb
|
60
|
+
</a>
|
61
|
+
<br />
|
62
|
+
</td>
|
63
|
+
</tr>
|
64
|
+
|
65
|
+
</table>
|
66
|
+
</div>
|
67
|
+
<!-- banner header -->
|
68
|
+
|
69
|
+
<div id="bodyContent">
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
<div id="contextContent">
|
74
|
+
|
75
|
+
<div id="description">
|
76
|
+
<p>
|
77
|
+
This class defines the annotation methods that are mixed into your Ruby
|
78
|
+
classes for XML mapping information and behavior.
|
79
|
+
</p>
|
80
|
+
<p>
|
81
|
+
See <a href="ROXML_Class.html#M000007">xml_name</a>, <a
|
82
|
+
href="ROXML_Class.html#M000009">xml_text</a>, <a
|
83
|
+
href="ROXML_Class.html#M000008">xml_attribute</a> and <a
|
84
|
+
href="ROXML_Class.html#M000010">xml_object</a> for available annotations.
|
85
|
+
</p>
|
86
|
+
|
87
|
+
</div>
|
88
|
+
|
89
|
+
|
90
|
+
</div>
|
91
|
+
|
92
|
+
<div id="method-list">
|
93
|
+
<h3 class="section-bar">Methods</h3>
|
94
|
+
|
95
|
+
<div class="name-list">
|
96
|
+
<a href="#M000006">parse</a>
|
97
|
+
<a href="#M000011">tag_name</a>
|
98
|
+
<a href="#M000012">tag_refs</a>
|
99
|
+
<a href="#M000008">xml_attribute</a>
|
100
|
+
<a href="#M000007">xml_name</a>
|
101
|
+
<a href="#M000010">xml_object</a>
|
102
|
+
<a href="#M000009">xml_text</a>
|
103
|
+
</div>
|
104
|
+
</div>
|
105
|
+
|
106
|
+
</div>
|
107
|
+
|
108
|
+
|
109
|
+
<!-- if includes -->
|
110
|
+
|
111
|
+
<div id="section">
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
<!-- if method_list -->
|
121
|
+
<div id="methods">
|
122
|
+
<h3 class="section-bar">Public Instance methods</h3>
|
123
|
+
|
124
|
+
<div id="method-M000006" class="method-detail">
|
125
|
+
<a name="M000006"></a>
|
126
|
+
|
127
|
+
<div class="method-heading">
|
128
|
+
<a href="ROXML_Class.src/M000006.html" target="Code" class="method-signature"
|
129
|
+
onclick="popupCode('ROXML_Class.src/M000006.html');return false;">
|
130
|
+
<span class="method-name">parse</span><span class="method-args">(data)</span>
|
131
|
+
</a>
|
132
|
+
</div>
|
133
|
+
|
134
|
+
<div class="method-description">
|
135
|
+
<p>
|
136
|
+
Creates a new Ruby object from XML using mapping information annotated in
|
137
|
+
the class.
|
138
|
+
</p>
|
139
|
+
<p>
|
140
|
+
The input data is either a REXML::Element or a <a
|
141
|
+
href="../String.html">String</a> representing the XML document.
|
142
|
+
</p>
|
143
|
+
<p>
|
144
|
+
Example
|
145
|
+
</p>
|
146
|
+
<pre>
|
147
|
+
book = Book.parse(File.read("book.xml"))
|
148
|
+
</pre>
|
149
|
+
<p>
|
150
|
+
or
|
151
|
+
</p>
|
152
|
+
<pre>
|
153
|
+
book = Book.parse("<book><name>Beyond Java</name></book>")
|
154
|
+
</pre>
|
155
|
+
</div>
|
156
|
+
</div>
|
157
|
+
|
158
|
+
<div id="method-M000011" class="method-detail">
|
159
|
+
<a name="M000011"></a>
|
160
|
+
|
161
|
+
<div class="method-heading">
|
162
|
+
<a href="ROXML_Class.src/M000011.html" target="Code" class="method-signature"
|
163
|
+
onclick="popupCode('ROXML_Class.src/M000011.html');return false;">
|
164
|
+
<span class="method-name">tag_name</span><span class="method-args">()</span>
|
165
|
+
</a>
|
166
|
+
</div>
|
167
|
+
|
168
|
+
<div class="method-description">
|
169
|
+
<p>
|
170
|
+
Returns the tag name (also known as <a
|
171
|
+
href="ROXML_Class.html#M000007">xml_name</a>) of the class. If no tag name
|
172
|
+
is set with <a href="ROXML_Class.html#M000007">xml_name</a> method, returns
|
173
|
+
default class name in lowercase.
|
174
|
+
</p>
|
175
|
+
</div>
|
176
|
+
</div>
|
177
|
+
|
178
|
+
<div id="method-M000012" class="method-detail">
|
179
|
+
<a name="M000012"></a>
|
180
|
+
|
181
|
+
<div class="method-heading">
|
182
|
+
<a href="ROXML_Class.src/M000012.html" target="Code" class="method-signature"
|
183
|
+
onclick="popupCode('ROXML_Class.src/M000012.html');return false;">
|
184
|
+
<span class="method-name">tag_refs</span><span class="method-args">()</span>
|
185
|
+
</a>
|
186
|
+
</div>
|
187
|
+
|
188
|
+
<div class="method-description">
|
189
|
+
<p>
|
190
|
+
Returns array of internal reference objects, such as attributes and
|
191
|
+
composed XML objects
|
192
|
+
</p>
|
193
|
+
</div>
|
194
|
+
</div>
|
195
|
+
|
196
|
+
<div id="method-M000008" class="method-detail">
|
197
|
+
<a name="M000008"></a>
|
198
|
+
|
199
|
+
<div class="method-heading">
|
200
|
+
<a href="ROXML_Class.src/M000008.html" target="Code" class="method-signature"
|
201
|
+
onclick="popupCode('ROXML_Class.src/M000008.html');return false;">
|
202
|
+
<span class="method-name">xml_attribute</span><span class="method-args">(sym, name = nil, options = 0)</span>
|
203
|
+
</a>
|
204
|
+
</div>
|
205
|
+
|
206
|
+
<div class="method-description">
|
207
|
+
<p>
|
208
|
+
Declare an accessor for the included class that should be represented as an
|
209
|
+
XML attribute.
|
210
|
+
</p>
|
211
|
+
<dl>
|
212
|
+
<dt>sym</dt><dd>Symbol representing the name of the accessor
|
213
|
+
|
214
|
+
</dd>
|
215
|
+
<dt>name</dt><dd>An optional name that should be used for the attribute in XML. Default is
|
216
|
+
sym.id2name.
|
217
|
+
|
218
|
+
</dd>
|
219
|
+
<dt>options</dt><dd>Valid options are TAG_READONLY to attribute as read-only
|
220
|
+
|
221
|
+
</dd>
|
222
|
+
</dl>
|
223
|
+
<p>
|
224
|
+
Example:
|
225
|
+
</p>
|
226
|
+
<pre>
|
227
|
+
class Book
|
228
|
+
xml_attribute :isbn, "ISBN"
|
229
|
+
end
|
230
|
+
</pre>
|
231
|
+
<p>
|
232
|
+
To map:
|
233
|
+
</p>
|
234
|
+
<pre>
|
235
|
+
<book ISBN="0974514055"></book>
|
236
|
+
</pre>
|
237
|
+
</div>
|
238
|
+
</div>
|
239
|
+
|
240
|
+
<div id="method-M000007" class="method-detail">
|
241
|
+
<a name="M000007"></a>
|
242
|
+
|
243
|
+
<div class="method-heading">
|
244
|
+
<a href="ROXML_Class.src/M000007.html" target="Code" class="method-signature"
|
245
|
+
onclick="popupCode('ROXML_Class.src/M000007.html');return false;">
|
246
|
+
<span class="method-name">xml_name</span><span class="method-args">(name)</span>
|
247
|
+
</a>
|
248
|
+
</div>
|
249
|
+
|
250
|
+
<div class="method-description">
|
251
|
+
<p>
|
252
|
+
Sets the name of the XML element that represents this class. Use this to
|
253
|
+
override the default lowercase class name.
|
254
|
+
</p>
|
255
|
+
<p>
|
256
|
+
Example:
|
257
|
+
</p>
|
258
|
+
<pre>
|
259
|
+
class BookWithPublisher
|
260
|
+
xml_name :book
|
261
|
+
end
|
262
|
+
</pre>
|
263
|
+
<p>
|
264
|
+
Without the <a href="ROXML_Class.html#M000007">xml_name</a> annotation, the
|
265
|
+
XML mapped tag would have been "bookwithpublisher".
|
266
|
+
</p>
|
267
|
+
</div>
|
268
|
+
</div>
|
269
|
+
|
270
|
+
<div id="method-M000010" class="method-detail">
|
271
|
+
<a name="M000010"></a>
|
272
|
+
|
273
|
+
<div class="method-heading">
|
274
|
+
<a href="ROXML_Class.src/M000010.html" target="Code" class="method-signature"
|
275
|
+
onclick="popupCode('ROXML_Class.src/M000010.html');return false;">
|
276
|
+
<span class="method-name">xml_object</span><span class="method-args">(sym, klass, options = 0, wrapper = nil)</span>
|
277
|
+
</a>
|
278
|
+
</div>
|
279
|
+
|
280
|
+
<div class="method-description">
|
281
|
+
<p>
|
282
|
+
Declares an accessor that represents another <a
|
283
|
+
href="../ROXML.html">ROXML</a> class as child XML element (one-to-one or
|
284
|
+
composition) or array of child elements (one-to-many or aggregation).
|
285
|
+
Default is one-to-one. Use TAG_ARRAY option for one-to-many.
|
286
|
+
</p>
|
287
|
+
<dl>
|
288
|
+
<dt>sym</dt><dd>Symbol representing the name of the accessor.
|
289
|
+
|
290
|
+
</dd>
|
291
|
+
<dt>name</dt><dd>An optional name that should be used for the attribute in XML. Default is
|
292
|
+
sym.id2name.
|
293
|
+
|
294
|
+
</dd>
|
295
|
+
<dt>options</dt><dd>TAG_ARRAY for one-to-many, and TAG_READONLY for read-only access.
|
296
|
+
|
297
|
+
</dd>
|
298
|
+
<dt>wrapper</dt><dd>An optional name of a wrapping tag for this XML accessor.
|
299
|
+
|
300
|
+
</dd>
|
301
|
+
</dl>
|
302
|
+
<p>
|
303
|
+
Composition example:
|
304
|
+
</p>
|
305
|
+
<pre>
|
306
|
+
<book>
|
307
|
+
<publisher>
|
308
|
+
<name>Pragmatic Bookshelf</name>
|
309
|
+
</publisher>
|
310
|
+
</book>
|
311
|
+
</pre>
|
312
|
+
<p>
|
313
|
+
Can be mapped using the following code:
|
314
|
+
</p>
|
315
|
+
<pre>
|
316
|
+
class Book
|
317
|
+
xml_object :publisher, Publisher
|
318
|
+
end
|
319
|
+
</pre>
|
320
|
+
<p>
|
321
|
+
Aggregation example:
|
322
|
+
</p>
|
323
|
+
<pre>
|
324
|
+
<library>
|
325
|
+
<name>Ruby books</name>
|
326
|
+
<books>
|
327
|
+
<book/>
|
328
|
+
<book/>
|
329
|
+
</books>
|
330
|
+
</library>
|
331
|
+
</pre>
|
332
|
+
<p>
|
333
|
+
Can be mapped using the following code:
|
334
|
+
</p>
|
335
|
+
<pre>
|
336
|
+
class Library
|
337
|
+
xml_text :name, nil, ROXML::TAG_CDATA
|
338
|
+
xml_object :books, Book, ROXML::TAG_ARRAY, "books"
|
339
|
+
end
|
340
|
+
</pre>
|
341
|
+
<p>
|
342
|
+
If you don’t have the <books> tag to wrap around the list of
|
343
|
+
<book> tags:
|
344
|
+
</p>
|
345
|
+
<pre>
|
346
|
+
<library>
|
347
|
+
<name>Ruby books</name>
|
348
|
+
<book/>
|
349
|
+
<book/>
|
350
|
+
</library>
|
351
|
+
</pre>
|
352
|
+
<p>
|
353
|
+
You can skip the wrapper argument:
|
354
|
+
</p>
|
355
|
+
<pre>
|
356
|
+
xml_object :books, Book, ROXML::TAG_ARRAY
|
357
|
+
</pre>
|
358
|
+
</div>
|
359
|
+
</div>
|
360
|
+
|
361
|
+
<div id="method-M000009" class="method-detail">
|
362
|
+
<a name="M000009"></a>
|
363
|
+
|
364
|
+
<div class="method-heading">
|
365
|
+
<a href="ROXML_Class.src/M000009.html" target="Code" class="method-signature"
|
366
|
+
onclick="popupCode('ROXML_Class.src/M000009.html');return false;">
|
367
|
+
<span class="method-name">xml_text</span><span class="method-args">(sym, name = nil, options = 0, wrapper = nil)</span>
|
368
|
+
</a>
|
369
|
+
</div>
|
370
|
+
|
371
|
+
<div class="method-description">
|
372
|
+
<p>
|
373
|
+
Declares an accessor that represents one or more XML text elements.
|
374
|
+
</p>
|
375
|
+
<dl>
|
376
|
+
<dt>sym</dt><dd>Symbol representing the name of the accessor.
|
377
|
+
|
378
|
+
</dd>
|
379
|
+
<dt>name</dt><dd>An optional name that should be used for the attribute in XML. Default is
|
380
|
+
sym.id2name.
|
381
|
+
|
382
|
+
</dd>
|
383
|
+
<dt>options</dt><dd>TAG_CDATA for character data, TAG_ARRAY for one-to-many, and TAG_READONLY
|
384
|
+
for read-only access.
|
385
|
+
|
386
|
+
</dd>
|
387
|
+
<dt>wrapper</dt><dd>An optional name of a wrapping tag for this XML accessor.
|
388
|
+
|
389
|
+
</dd>
|
390
|
+
</dl>
|
391
|
+
<p>
|
392
|
+
Example:
|
393
|
+
</p>
|
394
|
+
<pre>
|
395
|
+
class Book
|
396
|
+
xml_text :description, nil, ROXML::TAG_CDATA
|
397
|
+
end
|
398
|
+
</pre>
|
399
|
+
<p>
|
400
|
+
To map:
|
401
|
+
</p>
|
402
|
+
<pre>
|
403
|
+
<book>
|
404
|
+
<description><![CDATA[Probably the best Ruby book out there]]></description>
|
405
|
+
</book>
|
406
|
+
</pre>
|
407
|
+
</div>
|
408
|
+
</div>
|
409
|
+
|
410
|
+
|
411
|
+
</div>
|
412
|
+
|
413
|
+
|
414
|
+
</div>
|
415
|
+
|
416
|
+
|
417
|
+
<div id="validator-badges">
|
418
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
419
|
+
</div>
|
420
|
+
|
421
|
+
</body>
|
422
|
+
</html>
|