File: xmlextparser.rb

package info (click to toggle)
libxml-parser-ruby 0.6.1-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 676 kB
  • ctags: 800
  • sloc: ruby: 5,723; ansic: 1,734; xml: 574; makefile: 152
file content (39 lines) | stat: -rw-r--r-- 1,030 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
require 'xmlparser'

module XML
  class ExtParser < Parser

    def readResource(base, systemId, publicId = nil)
      systemId = base + systemId unless base.nil?
      open(systemId).read
    end

    def parse(*args)
      setParamEntityParsing(XMLParser::PARAM_ENTITY_PARSING_UNLESS_STANDALONE)

      if iterator?
        super(*args) do |event, name, data|
          if (event ==  XMLParser::EXTERNAL_ENTITY_REF)
            base, systemId, publicId = data
            extp = type.new(self, name)
            extp.parse(readResource(base, systemId)) do |event, name, data|
              yield(event, name, data)
            end
            extp.done
          else
            yield(event, name, data)
          end
        end
      else
        super(*args)
      end
    end

    def externalEntityRef(context, base, systemId, publicId)
##      p ["externalEntityRef", context, base, systemId, publicId]
      extp = type.new(self, context)
      extp.parse(readResource(base, systemId))
      extp.done
    end
  end
end