File: extdtd.rb

package info (click to toggle)
libxml-parser-ruby 0.6.8-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 912 kB
  • ctags: 1,523
  • sloc: ruby: 11,080; ansic: 1,958; xml: 467; makefile: 59
file content (34 lines) | stat: -rwxr-xr-x 745 bytes parent folder | download | duplicates (3)
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
#! /usr/local/bin/ruby

require 'xml/parser'

class ExtDTDParser < XML::Parser
  def startElement(name, attr)
    p ["startElement", name, attr]
  end

  def endElement(name)
    p ["endElement", name]
  end

  def character(data)
    p ["character", data]
  end

  def externalEntityRef(context, base, systemId, publicId)
    p ["externalEntityRef", context, base, systemId, publicId]
    extp = ExtDTDParser.new(self, context)
    extp.parse(open(systemId).read)
    extp.done ## required
  end
end

p = ExtDTDParser.new(nil, '!')
if p.respond_to?(:setParamEntityParsing)
  p.setParamEntityParsing(XML::Parser::PARAM_ENTITY_PARSING_UNLESS_STANDALONE)
end
begin
  p.parse($<.read)
rescue XML::Parser::Error
  print "#{$!} in l.#{p.line}\n"
end