Class: FeedParser::Expat::StrictFeedParser
- Inherits:
-
Object
- Object
- FeedParser::Expat::StrictFeedParser
- Defined in:
- lib/rfeedparser/expat_parser.rb
Instance Attribute Summary collapse
-
#handler ⇒ Object
readonly
Returns the value of attribute handler.
Instance Method Summary collapse
-
#initialize(baseuri, baselang) ⇒ StrictFeedParser
constructor
A new instance of StrictFeedParser.
- #parse(data) ⇒ Object
Constructor Details
#initialize(baseuri, baselang) ⇒ StrictFeedParser
Returns a new instance of StrictFeedParser.
16 17 18 |
# File 'lib/rfeedparser/expat_parser.rb', line 16 def initialize(baseuri, baselang) @handler = StrictFeedParserHandler.new(baseuri, baselang, 'utf-8') end |
Instance Attribute Details
#handler ⇒ Object (readonly)
Returns the value of attribute handler.
15 16 17 |
# File 'lib/rfeedparser/expat_parser.rb', line 15 def handler @handler end |
Instance Method Details
#parse(data) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rfeedparser/expat_parser.rb', line 20 def parse(data) # initialize the SAX parser saxparser = XML::SAX::Helpers::ParserFactory.makeParser("XML::Parser::SAXDriver") saxparser.setDocumentHandler(@handler) saxparser.setDTDHandler(@handler) saxparser.setEntityResolver(@handler) saxparser.setErrorHandler(@handler) inputdata = XML::SAX::InputSource.new('parsedfeed') inputdata.setByteStream(StringIO.new(data)) begin saxparser.parse(inputdata) rescue XML::SAX::SAXParseException => err # This does not inherit from StandardError as it should, so # we have to catch and re-raise specially. raise err.to_s end end |