ROXML 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. data/.gitignore +6 -0
  2. data/.gitmodules +3 -0
  3. data/History.txt +299 -0
  4. data/MIT-LICENSE +18 -0
  5. data/README.rdoc +161 -0
  6. data/Rakefile +95 -0
  7. data/TODO +39 -0
  8. data/VERSION +1 -0
  9. data/config/website.yml +2 -0
  10. data/examples/amazon.rb +35 -0
  11. data/examples/current_weather.rb +27 -0
  12. data/examples/dashed_elements.rb +20 -0
  13. data/examples/library.rb +40 -0
  14. data/examples/posts.rb +27 -0
  15. data/examples/rails.rb +70 -0
  16. data/examples/twitter.rb +37 -0
  17. data/examples/xml/active_record.xml +70 -0
  18. data/examples/xml/amazon.xml +133 -0
  19. data/examples/xml/current_weather.xml +89 -0
  20. data/examples/xml/dashed_elements.xml +52 -0
  21. data/examples/xml/posts.xml +23 -0
  22. data/examples/xml/twitter.xml +422 -0
  23. data/lib/roxml.rb +547 -0
  24. data/lib/roxml/definition.rb +236 -0
  25. data/lib/roxml/hash_definition.rb +25 -0
  26. data/lib/roxml/xml.rb +43 -0
  27. data/lib/roxml/xml/parsers/libxml.rb +91 -0
  28. data/lib/roxml/xml/parsers/nokogiri.rb +77 -0
  29. data/lib/roxml/xml/references.rb +297 -0
  30. data/roxml.gemspec +201 -0
  31. data/spec/definition_spec.rb +486 -0
  32. data/spec/examples/active_record_spec.rb +40 -0
  33. data/spec/examples/amazon_spec.rb +54 -0
  34. data/spec/examples/current_weather_spec.rb +37 -0
  35. data/spec/examples/dashed_elements_spec.rb +20 -0
  36. data/spec/examples/library_spec.rb +46 -0
  37. data/spec/examples/post_spec.rb +24 -0
  38. data/spec/examples/twitter_spec.rb +32 -0
  39. data/spec/roxml_spec.rb +372 -0
  40. data/spec/shared_specs.rb +15 -0
  41. data/spec/spec.opts +1 -0
  42. data/spec/spec_helper.rb +14 -0
  43. data/spec/support/libxml.rb +3 -0
  44. data/spec/support/nokogiri.rb +3 -0
  45. data/spec/xml/attributes_spec.rb +36 -0
  46. data/spec/xml/namespace_spec.rb +240 -0
  47. data/spec/xml/namespaces_spec.rb +32 -0
  48. data/spec/xml/parser_spec.rb +26 -0
  49. data/tasks/rdoc.rake +13 -0
  50. data/tasks/rspec.rake +25 -0
  51. data/tasks/test.rake +35 -0
  52. data/test/fixtures/book_malformed.xml +5 -0
  53. data/test/fixtures/book_pair.xml +8 -0
  54. data/test/fixtures/book_text_with_attribute.xml +5 -0
  55. data/test/fixtures/book_valid.xml +5 -0
  56. data/test/fixtures/book_with_authors.xml +7 -0
  57. data/test/fixtures/book_with_contributions.xml +9 -0
  58. data/test/fixtures/book_with_contributors.xml +7 -0
  59. data/test/fixtures/book_with_contributors_attrs.xml +7 -0
  60. data/test/fixtures/book_with_default_namespace.xml +9 -0
  61. data/test/fixtures/book_with_depth.xml +6 -0
  62. data/test/fixtures/book_with_octal_pages.xml +4 -0
  63. data/test/fixtures/book_with_publisher.xml +7 -0
  64. data/test/fixtures/book_with_wrapped_attr.xml +3 -0
  65. data/test/fixtures/dictionary_of_attr_name_clashes.xml +8 -0
  66. data/test/fixtures/dictionary_of_attrs.xml +6 -0
  67. data/test/fixtures/dictionary_of_guarded_names.xml +6 -0
  68. data/test/fixtures/dictionary_of_mixeds.xml +4 -0
  69. data/test/fixtures/dictionary_of_name_clashes.xml +10 -0
  70. data/test/fixtures/dictionary_of_names.xml +4 -0
  71. data/test/fixtures/dictionary_of_texts.xml +10 -0
  72. data/test/fixtures/library.xml +30 -0
  73. data/test/fixtures/library_uppercase.xml +30 -0
  74. data/test/fixtures/muffins.xml +3 -0
  75. data/test/fixtures/nameless_ageless_youth.xml +2 -0
  76. data/test/fixtures/node_with_attr_name_conflicts.xml +1 -0
  77. data/test/fixtures/node_with_name_conflicts.xml +4 -0
  78. data/test/fixtures/numerology.xml +4 -0
  79. data/test/fixtures/person.xml +1 -0
  80. data/test/fixtures/person_with_guarded_mothers.xml +13 -0
  81. data/test/fixtures/person_with_mothers.xml +10 -0
  82. data/test/mocks/dictionaries.rb +57 -0
  83. data/test/mocks/mocks.rb +279 -0
  84. data/test/support/fixtures.rb +11 -0
  85. data/test/test_helper.rb +34 -0
  86. data/test/unit/definition_test.rb +235 -0
  87. data/test/unit/deprecations_test.rb +24 -0
  88. data/test/unit/to_xml_test.rb +81 -0
  89. data/test/unit/xml_attribute_test.rb +39 -0
  90. data/test/unit/xml_block_test.rb +81 -0
  91. data/test/unit/xml_bool_test.rb +122 -0
  92. data/test/unit/xml_convention_test.rb +150 -0
  93. data/test/unit/xml_hash_test.rb +115 -0
  94. data/test/unit/xml_initialize_test.rb +49 -0
  95. data/test/unit/xml_name_test.rb +141 -0
  96. data/test/unit/xml_namespace_test.rb +31 -0
  97. data/test/unit/xml_object_test.rb +207 -0
  98. data/test/unit/xml_required_test.rb +94 -0
  99. data/test/unit/xml_text_test.rb +71 -0
  100. data/website/index.html +98 -0
  101. metadata +254 -0
@@ -0,0 +1,5 @@
1
+ <book isbn="0201710897">
2
+ <title>The PickAxe<title>
3
+ <description><![CDATA[Probably the best Ruby book out there]]></description>
4
+ <author>David Thomas, Andrew Hunt, Dave Thomas</author>
5
+ </book>
@@ -0,0 +1,8 @@
1
+ <book isbn="0974514055">
2
+ <title>Programming Ruby - 2nd Edition</title>
3
+ <description>Second edition of the great book out there</description>
4
+ <book isbn="0974514055">
5
+ <title>Agile Web Development with Rails</title>
6
+ <description>Jolt winning original Ruby on Rails book</description>
7
+ </book>
8
+ </book>
@@ -0,0 +1,5 @@
1
+ <book ISBN="0201710897">
2
+ <title>The PickAxe</title>
3
+ <description><![CDATA[Probably the best Ruby book out there]]></description>
4
+ <author role="primary">David Thomas</author>
5
+ </book>
@@ -0,0 +1,5 @@
1
+ <book ISBN="0201710897">
2
+ <title>The PickAxe</title>
3
+ <description><![CDATA[Probably the best Ruby book out there]]></description>
4
+ <author>David Thomas, Andrew Hunt &amp; Dave Thomas</author>
5
+ <pagecount>357</pagecount></book>
@@ -0,0 +1,7 @@
1
+ <book ISBN="0201710897">
2
+ <title>The PickAxe</title>
3
+ <description><![CDATA[Probably the best Ruby book out there]]></description>
4
+ <author>David Thomas</author>
5
+ <author>Andrew Hunt</author>
6
+ <author>Dave Thomas</author>
7
+ </book>
@@ -0,0 +1,9 @@
1
+ <book isbn="0974514055">
2
+ <title>Programming Ruby - 2nd Edition</title>
3
+ <description>Second edition of the great book out there</description>
4
+ <contributions>
5
+ <contributor role="author"><name>David Thomas</name></contributor>
6
+ <contributor role="supporting author"><name>Andrew Hunt</name></contributor>
7
+ <contributor role="supporting author"><name>Chad Fowler</name></contributor>
8
+ </contributions>
9
+ </book>
@@ -0,0 +1,7 @@
1
+ <book isbn="0974514055">
2
+ <title>Programming Ruby - 2nd Edition</title>
3
+ <description>Second edition of the great book out there</description>
4
+ <contributor role="author"><name>David Thomas</name></contributor>
5
+ <contributor role="supporting author"><name>Andrew Hunt</name></contributor>
6
+ <contributor role="supporting author"><name>Chad Fowler</name></contributor>
7
+ </book>
@@ -0,0 +1,7 @@
1
+ <book isbn="0974514055">
2
+ <title>Programming Ruby - 2nd Edition</title>
3
+ <description>Second edition of the great book out there</description>
4
+ <contributor role="author" name="David Thomas" />
5
+ <contributor role="supporting author" name="Andrew Hunt" />
6
+ <contributor role="supporting author" name="Chad Fowler" />
7
+ </book>
@@ -0,0 +1,9 @@
1
+ <book xmlns="http://booknamespace.org" isbn="0974514055">
2
+ <title>Programming Ruby - 2nd Edition</title>
3
+ <description>Second edition of the great book out there</description>
4
+ <contributions>
5
+ <contributor role="author"><name>David Thomas</name></contributor>
6
+ <contributor role="supporting author"><name>Andrew Hunt</name></contributor>
7
+ <contributor role="supporting author"><name>Chad Fowler</name></contributor>
8
+ </contributions>
9
+ </book>
@@ -0,0 +1,6 @@
1
+ <book ISBN="0201710897">
2
+ <title>The PickAxe</title>
3
+ <description><![CDATA[Probably the best Ruby book out there]]></description>
4
+ <author>David Thomas, Andrew Hunt, Dave Thomas</author>
5
+ <depth units="hundredths-meters">1130</depth>
6
+ </book>
@@ -0,0 +1,4 @@
1
+ <bookwithoctalpages>
2
+ <pages_with_to_xml_proc>0357</pages_with_to_xml_proc>
3
+ <pages_with_type>0357</pages_with_type>
4
+ </bookwithoctalpages>
@@ -0,0 +1,7 @@
1
+ <book isbn="0974514055">
2
+ <title>Programming Ruby - 2nd Edition</title>
3
+ <description>Second edition of the great book out there</description>
4
+ <publisher>
5
+ <name>Pragmatic Bookshelf</name>
6
+ </publisher>
7
+ </book>
@@ -0,0 +1,3 @@
1
+ <book>
2
+ <ids ISBN="0974514055" />
3
+ </book>
@@ -0,0 +1,8 @@
1
+ <dictionary>
2
+ <definition name="quaquaversally">
3
+ <content>adjective: (of a geological formation) sloping downward from the center in all directions.</content>
4
+ </definition>
5
+ <definition name="tergiversate">
6
+ <content>To use evasions or ambiguities; equivocate.</content>
7
+ </definition>
8
+ </dictionary>
@@ -0,0 +1,6 @@
1
+ <dictionary>
2
+ <definitions>
3
+ <definition dt="quaquaversally" dd="adjective: (of a geological formation) sloping downward from the center in all directions." />
4
+ <definition dt="tergiversate" dd="To use evasions or ambiguities; equivocate." />
5
+ </definitions>
6
+ </dictionary>
@@ -0,0 +1,6 @@
1
+ <dictionary>
2
+ <definitions>
3
+ <quaquaversally>adjective: (of a geological formation) sloping downward from the center in all directions.</quaquaversally>
4
+ <tergiversate>To use evasions or ambiguities; equivocate.</tergiversate>
5
+ </definitions>
6
+ </dictionary>
@@ -0,0 +1,4 @@
1
+ <dictionary>
2
+ <definition word="quaquaversally">adjective: (of a geological formation) sloping downward from the center in all directions.</definition>
3
+ <definition word="tergiversate">To use evasions or ambiguities; equivocate.</definition>
4
+ </dictionary>
@@ -0,0 +1,10 @@
1
+ <dictionary>
2
+ <definition>
3
+ <name>quaquaversally</name>
4
+ <content>adjective: (of a geological formation) sloping downward from the center in all directions.</content>
5
+ </definition>
6
+ <definition>
7
+ <name>tergiversate</name>
8
+ <content>To use evasions or ambiguities; equivocate.</content>
9
+ </definition>
10
+ </dictionary>
@@ -0,0 +1,4 @@
1
+ <dictionary>
2
+ <quaquaversally>adjective: (of a geological formation) sloping downward from the center in all directions.</quaquaversally>
3
+ <tergiversate>To use evasions or ambiguities; equivocate.</tergiversate>
4
+ </dictionary>
@@ -0,0 +1,10 @@
1
+ <dictionary>
2
+ <definition>
3
+ <word>quaquaversally</word>
4
+ <meaning>adjective: (of a geological formation) sloping downward from the center in all directions.</meaning>
5
+ </definition>
6
+ <definition>
7
+ <word>tergiversate</word>
8
+ <meaning>To use evasions or ambiguities; equivocate.</meaning>
9
+ </definition>
10
+ </dictionary>
@@ -0,0 +1,30 @@
1
+ <library>
2
+ <name>Ruby library</name>
3
+ <book isbn="0974514055">
4
+ <title>Programming Ruby - 2nd Edition</title>
5
+ <description>Second edition of the great book out there</description>
6
+ <contributions>
7
+ <contributor role="author">
8
+ <name>David Thomas</name>
9
+ </contributor>
10
+ <contributor role="supporting author">
11
+ <name>Andrew Hunt</name>
12
+ </contributor>
13
+ <contributor role="supporting author">
14
+ <name>Chad Fowler</name>
15
+ </contributor>
16
+ </contributions>
17
+ </book>
18
+ <book isbn="0974514055">
19
+ <title>Agile Web Development with Rails</title>
20
+ <description>Jolt winning original Ruby on Rails book</description>
21
+ <contributions>
22
+ <contributor role="author">
23
+ <name>David Thomas</name>
24
+ </contributor>
25
+ <contributor role="author">
26
+ <name>David Heinemeier Hansson</name>
27
+ </contributor>
28
+ </contributions>
29
+ </book>
30
+ </library>
@@ -0,0 +1,30 @@
1
+ <library>
2
+ <NAME>Ruby library</NAME>
3
+ <BOOK isbn="0974514055">
4
+ <title>Programming Ruby - 2nd Edition</title>
5
+ <description>Second edition of the great book out there</description>
6
+ <contributions>
7
+ <contributor role="author">
8
+ <name>David Thomas</name>
9
+ </contributor>
10
+ <contributor role="supporting author">
11
+ <name>Andrew Hunt</name>
12
+ </contributor>
13
+ <contributor role="supporting author">
14
+ <name>Chad Fowler</name>
15
+ </contributor>
16
+ </contributions>
17
+ </BOOK>
18
+ <BOOK isbn="0974514055">
19
+ <title>Agile Web Development with Rails</title>
20
+ <description>Jolt winning original Ruby on Rails book</description>
21
+ <contributions>
22
+ <contributor role="author">
23
+ <name>David Thomas</name>
24
+ </contributor>
25
+ <contributor role="author">
26
+ <name>David Heinemeier Hansson</name>
27
+ </contributor>
28
+ </contributions>
29
+ </BOOK>
30
+ </library>
@@ -0,0 +1,3 @@
1
+ <muffins>
2
+ <bakers_dozens>3</bakers_dozens>
3
+ </muffins>
@@ -0,0 +1,2 @@
1
+ <person>
2
+ </person>
@@ -0,0 +1 @@
1
+ <node content="Just junk... really" name="Cartwheel" />
@@ -0,0 +1,4 @@
1
+ <node>
2
+ <content>Just junk... really</content>
3
+ <name>Cartwheel</name>
4
+ </node>
@@ -0,0 +1,4 @@
1
+ <numerology>
2
+ <prediction number="13" meaning="A bad number" />
3
+ <prediction number="7" meaning="A good number" />
4
+ </numerology>
@@ -0,0 +1 @@
1
+ <person>Ben Franklin</person>
@@ -0,0 +1,13 @@
1
+ <person>
2
+ <name>Ben &quot;Benji&quot; Franklin</name>
3
+ <mother>
4
+ <person>
5
+ <name>Abiah &apos;Abby&apos; Folger</name>
6
+ <mother>
7
+ <person>
8
+ <name>Madeup Mother &lt; the third &gt;</name>
9
+ </person>
10
+ </mother>
11
+ </person>
12
+ </mother>
13
+ </person>
@@ -0,0 +1,10 @@
1
+ <person>
2
+ <name>Ben Franklin</name>
3
+ <mother>
4
+ <name>Abiah Folger</name>
5
+ <mother>
6
+ <name>Madeup Mother</name>
7
+ </mother>
8
+ </mother>
9
+ </person>
10
+
@@ -0,0 +1,57 @@
1
+ require 'lib/roxml'
2
+
3
+ class DictionaryOfAttrs
4
+ include ROXML
5
+
6
+ xml_name :dictionary
7
+ xml_reader :definitions, :as => {:key => '@dt',
8
+ :value => '@dd'}, :in => :definitions
9
+ end
10
+
11
+ class DictionaryOfTexts
12
+ include ROXML
13
+
14
+ xml_name :dictionary
15
+ xml_reader :definitions, :as => {:key => :word,
16
+ :value => :meaning}
17
+ end
18
+
19
+ class DictionaryOfMixeds
20
+ include ROXML
21
+
22
+ xml_name :dictionary
23
+ xml_reader :definitions, :as => {:key => '@word',
24
+ :value => :content}
25
+ end
26
+
27
+ class DictionaryOfNames
28
+ include ROXML
29
+
30
+ xml_name :dictionary
31
+ xml_reader :definitions, :as => {:key => :name,
32
+ :value => :content}
33
+ end
34
+
35
+ class DictionaryOfGuardedNames
36
+ include ROXML
37
+
38
+ xml_name :dictionary
39
+ xml_reader :definitions, :as => {:key => :name,
40
+ :value => :content}, :in => :definitions
41
+ end
42
+
43
+ class DictionaryOfNameClashes
44
+ include ROXML
45
+
46
+ xml_name :dictionary
47
+ xml_reader :definitions, :as => {:key => 'name',
48
+ :value => 'content'}, :from => :definition
49
+ end
50
+
51
+ class DictionaryOfAttrNameClashes
52
+ include ROXML
53
+
54
+ xml_name :dictionary
55
+ xml_reader :definitions, :as => {:key => '@name',
56
+ :value => 'content'}, :from => :definition
57
+ end
@@ -0,0 +1,279 @@
1
+ require "lib/roxml"
2
+
3
+ class Muffins
4
+ include ROXML
5
+
6
+ xml_reader(:count, :from => 'bakers_dozens') {|val| val.to_i * 13 }
7
+ end
8
+
9
+ class MuffinsWithStackedBlocks
10
+ include ROXML
11
+
12
+ xml_reader(:count, :from => 'bakers_dozens', :as => Integer) {|val| val * 13 }
13
+ end
14
+
15
+ class Numerology
16
+ include ROXML
17
+
18
+ xml_reader :predictions, :as => {:key => '@number', :value => '@meaning'} do |k, v|
19
+ [Integer(k), v]
20
+ end
21
+ end
22
+
23
+ class Contributor
24
+ include ROXML
25
+
26
+ xml_reader :role, :from => :attr
27
+ xml_reader :name
28
+ end
29
+
30
+ class WriteableContributor
31
+ include ROXML
32
+
33
+ xml_accessor :role, :from => :attr
34
+ xml_accessor :name
35
+ end
36
+
37
+ class Book
38
+ include ROXML
39
+
40
+ xml_accessor :isbn, :from => '@ISBN'
41
+ xml_reader :title
42
+ xml_reader :description, :cdata => true
43
+ xml_reader :author
44
+ xml_accessor :pages, :from => 'pagecount', :as => Integer
45
+ end
46
+
47
+ class BookWithRequired
48
+ include ROXML
49
+
50
+ xml_accessor :isbn, :from => '@ISBN', :required => true
51
+ xml_reader :title, :required => true
52
+ xml_reader :contributors, :as => [Contributor], :in => 'contributor_array', :required => true
53
+ xml_reader :contributor_hash, :as => {:key => '@role', :value => '@name'},
54
+ :from => 'contributor', :in => 'contributor_hash', :required => true
55
+ end
56
+
57
+ class BookWithAttrFrom
58
+ include ROXML
59
+
60
+ xml_accessor :isbn, :from => '@ISBN'
61
+ end
62
+
63
+ class BookWithWrappedAttr
64
+ include ROXML
65
+
66
+ xml_name :book
67
+ xml_accessor :isbn, :from => '@ISBN', :in => 'ids'
68
+ end
69
+
70
+ class Measurement
71
+ include ROXML
72
+
73
+ xml_reader :units, :from => :attr
74
+ xml_reader :value, :from => :content, :as => Float
75
+
76
+ def initialize(value = 0, units = 'pixels')
77
+ @value = Float(value)
78
+ @units = units.to_s
79
+ normalize_hundredths
80
+ end
81
+
82
+ def to_s
83
+ "#{value} #{units}"
84
+ end
85
+
86
+ def ==(other)
87
+ other.units == @units && other.value == @value
88
+ end
89
+
90
+ private
91
+ def after_parse
92
+ normalize_hundredths
93
+ end
94
+
95
+ def normalize_hundredths
96
+ if @units.starts_with? 'hundredths-'
97
+ @value /= 100
98
+ @units = @units.split('hundredths-')[1]
99
+ end
100
+ end
101
+ end
102
+
103
+ class BookWithDepth
104
+ include ROXML
105
+
106
+ xml_reader :isbn, :from => '@ISBN'
107
+ xml_reader :title
108
+ xml_reader :description, :cdata => true
109
+ xml_reader :author
110
+ xml_reader :depth, :as => Measurement
111
+ end
112
+
113
+ class Author
114
+ include ROXML
115
+
116
+ xml_reader :role, :from => :attr
117
+ xml_reader :text, :from => :content
118
+ end
119
+
120
+ class BookWithAuthors
121
+ include ROXML
122
+
123
+ xml_name :book
124
+ xml_reader :isbn, :from => '@ISBN'
125
+ xml_reader :title
126
+ xml_reader :description, :cdata => true
127
+ xml_reader :authors, :as => []
128
+ end
129
+
130
+ class BookWithAuthorTextAttribute
131
+ include ROXML
132
+
133
+ xml_name :book
134
+ xml_reader :isbn, :from => '@ISBN'
135
+ xml_reader :title
136
+ xml_reader :description, :cdata => true
137
+ xml_reader :author, :as => Author
138
+ end
139
+
140
+ class BookWithContributions
141
+ include ROXML
142
+
143
+ xml_name :book
144
+ xml_reader :isbn, :from => :attr
145
+ xml_reader :title
146
+ xml_reader :description
147
+ xml_reader :contributions, :as => [Contributor], :from => 'contributor', :in => "contributions"
148
+ end
149
+
150
+ class BookWithContributors
151
+ include ROXML
152
+
153
+ xml_name :book
154
+ xml_reader :isbn, :from => :attr
155
+ xml_reader :title
156
+ xml_reader :description
157
+ xml_reader :contributors, :as => [Contributor]
158
+ end
159
+
160
+ class WriteableBookWithContributors
161
+ include ROXML
162
+
163
+ xml_name :book
164
+ xml_accessor :isbn, :from => :attr
165
+ xml_accessor :title
166
+ xml_accessor :description
167
+ xml_accessor :contributors, :as => [Contributor]
168
+ end
169
+
170
+ class NamelessBook
171
+ include ROXML
172
+
173
+ xml_reader :isbn, :from => :attr
174
+ xml_reader :title
175
+ xml_reader :description
176
+ xml_reader :contributors, :as => [Contributor]
177
+ end
178
+
179
+ class Publisher
180
+ include ROXML
181
+
182
+ xml_reader :name
183
+ end
184
+
185
+ class BookWithPublisher
186
+ include ROXML
187
+
188
+ xml_reader :book
189
+ xml_reader :isbn, :from => :attr
190
+ xml_reader :title
191
+ xml_reader :description
192
+ xml_reader :publisher, :as => Publisher
193
+ end
194
+
195
+ class BookPair
196
+ include ROXML
197
+
198
+ xml_reader :isbn, :from => :attr
199
+ xml_reader :title
200
+ xml_reader :description
201
+ xml_reader :author
202
+ xml_reader :book, :as => Book
203
+ end
204
+
205
+ class Library
206
+ include ROXML
207
+
208
+ xml_reader :name
209
+ xml_reader :books, :as => [BookWithContributions]
210
+ end
211
+
212
+ class UppercaseLibrary
213
+ include ROXML
214
+
215
+ xml_name :library
216
+ xml_reader :name, :from => 'NAME'
217
+ xml_reader :books, :as => [BookWithContributions], :from => 'BOOK'
218
+ end
219
+
220
+ class LibraryWithBooksOfUnderivableName
221
+ include ROXML
222
+
223
+ xml_accessor :name
224
+ xml_reader :novels, :as => [NamelessBook]
225
+ end
226
+
227
+ class NodeWithNameConflicts
228
+ include ROXML
229
+
230
+ xml_name :node
231
+ xml_reader :content
232
+ xml_reader :name
233
+ end
234
+
235
+ class NodeWithAttrNameConflicts
236
+ include ROXML
237
+
238
+ xml_name :node
239
+ xml_reader :content, :from => '@content'
240
+ xml_reader :name, :from => '@name'
241
+ end
242
+
243
+ class Person
244
+ include ROXML
245
+
246
+ xml_accessor :age, :from => :attr, :else => 21
247
+ xml_accessor :name, :from => :content, :else => 'Unknown'
248
+
249
+ def self.blank
250
+ new.tap do |instance|
251
+ instance.age = 21
252
+ instance.name = 'Unknown'
253
+ end
254
+ end
255
+ end
256
+
257
+ class PersonWithMother
258
+ include ROXML
259
+
260
+ xml_name :person
261
+ xml_reader :name
262
+ xml_reader :mother, :as => PersonWithMother, :from => 'mother'
263
+ end
264
+
265
+ class PersonWithGuardedMother
266
+ include ROXML
267
+
268
+ xml_name :person
269
+ xml_reader :name
270
+ xml_reader :mother, :as => PersonWithGuardedMother, :from => :person, :in => :mother
271
+ end
272
+
273
+ class PersonWithMotherOrMissing
274
+ include ROXML
275
+
276
+ xml_reader :age, :from => :attr, :else => 21
277
+ xml_reader :name, :else => 'Anonymous'
278
+ xml_reader :mother,:as => PersonWithMotherOrMissing, :else => Person.blank
279
+ end