PageRenderTime 21ms CodeModel.GetById 11ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/tools/Ruby/lib/ruby/1.8/xsd/xmlparser/rexmlparser.rb

http://github.com/agross/netopenspace
Ruby | 54 lines | 31 code | 16 blank | 7 comment | 1 complexity | 68b26ce67f9da61e6d71079c50ee5985 MD5 | raw file
 1# XSD4R - REXMLParser XML parser library.
 2# Copyright (C) 2002, 2003  NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
 3
 4# This program is copyrighted free software by NAKAMURA, Hiroshi.  You can
 5# redistribute it and/or modify it under the same terms of Ruby's license;
 6# either the dual license version in 2003, or any later version.
 7
 8
 9require 'xsd/xmlparser'
10require 'rexml/streamlistener'
11require 'rexml/document'
12
13
14module XSD
15module XMLParser
16
17
18class REXMLParser < XSD::XMLParser::Parser
19  include REXML::StreamListener
20
21  def do_parse(string_or_readable)
22    source = nil
23    source = REXML::SourceFactory.create_from(string_or_readable)
24    source.encoding = charset if charset
25    # Listener passes a String in utf-8.
26    @charset = 'utf-8'
27    REXML::Document.parse_stream(source, self)
28  end
29
30  def epilogue
31  end
32
33  def tag_start(name, attrs)
34    start_element(name, attrs)
35  end
36
37  def tag_end(name)
38    end_element(name)
39  end
40
41  def text(text)
42    characters(text)
43  end
44
45  def xmldecl(version, encoding, standalone)
46    # Version should be checked.
47  end
48
49  add_factory(self)
50end
51
52
53end
54end