[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

sax parsing

Shweta Kadam

5/7/2008 9:55:00 AM

hi all,
Has anybody used sax parsing in ruby
--
Posted via http://www.ruby-....

3 Answers

Robert Klemme

5/7/2008 11:01:00 AM

0

2008/5/7 Shweta Kadam <shweta_kadam@persistent.co.in>:

> Has anybody used sax parsing in ruby

Yes.

--
use.inject do |as, often| as.you_can - without end

Shweta Kadam

5/7/2008 11:07:00 AM

0

hi,
I'm using sax parsing in my code but confused about how to add
listener's to it and can you tell me in detail how to write sax code in
ruby as well as listener's.



--
Posted via http://www.ruby-....

Robert Dober

5/7/2008 5:08:00 PM

0

On Wed, May 7, 2008 at 1:07 PM, Shweta Kadam
<shweta_kadam@persistent.co.in> wrote:
#
# There are more ways, but I like most to use blocks
# If you prefer to implement listeners as objects the documentation below
# should give you some sound hints too, I just never felt the need for it.
#
require 'rexml/parsers/sax2parser'

parser = REXML::Parsers::SAX2Parser.new( DATA.read )

parser.listen :start_element do
|uri, locname, qname, atts|

puts "I am in start_element and was called with " <<
[uri, locname, qname, atts].inspect
end

parser.listen :characters do
| text |
puts %<I am in characters and was called with "#{text}">
end
#
# For all type of listeners see here:
# http://www.ruby-doc.org/core/classes/REXML/Parsers/SAX2Parser.ht...
# and for the paramters they take have a look at the corresponding method here:
# http://www.ruby-doc.org/core/classes/REXML/SAX2Lis...
parser.parse

__END__
<root>
<node1>
<node2 att1="www">
content
</node2>
</node1>
</root>


HTH
Robert

--
http://ruby-smalltalk.blo...

---
Whereof one cannot speak, thereof one must be silent.
Ludwig Wittgenstein