Skip to content

Commit

Permalink
fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
gregwebs committed May 17, 2011
1 parent 8e1cac5 commit 2891845
Showing 1 changed file with 31 additions and 29 deletions.
60 changes: 31 additions & 29 deletions README.textile
Expand Up @@ -62,35 +62,37 @@ response.messages.last # => "world"

h3. attribute and value

class AuthorElement
include SAXMachine
value :name
attribute :role
end
class ItemElement
include SAXMachine
element :title
elements :author, :as => :authors, :class => AuthorElement
end

item = ItemElement.parse(xml = <<-XML)
<item id="1">
<title>sweet</title>
<author role="writer">John Doe</author>
<author role="artist">Jane Doe</author>
</item>
XML

item.title # => 'sweet'
item.authors.first.name # => 'John Doe'
item.authors.last.role # => 'artist'

class AuthorRoles
include SAXMachine
elements :author, :as => :roles, :value => :role
end

AuthorRoles.parse(xml = <<-XML).parse.roles # => ['writer', 'artist']
<pre>
class AuthorElement
include SAXMachine
value :name
attribute :role
end
class ItemElement
include SAXMachine
element :title
elements :author, :as => :authors, :class => AuthorElement
end

item = ItemElement.parse(xml = <<-XML)
<item id="1">
<title>sweet</title>
<author role="writer">John Doe</author>
<author role="artist">Jane Doe</author>
</item>
XML

item.title # => 'sweet'
item.authors.first.name # => 'John Doe'
item.authors.last.role # => 'artist'

class AuthorRoles
include SAXMachine
elements :author, :as => :roles, :value => :role
end

AuthorRoles.parse(xml = <<-XML).parse.roles # => ['writer', 'artist']
</pre>


h3. Laziness/Enumerator - Constant memory usage
Expand Down

0 comments on commit 2891845

Please sign in to comment.