File: useforeigndtd.rb

package info (click to toggle)
libxml-parser-ruby 0.6.8-4
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 932 kB
  • ctags: 1,525
  • sloc: ruby: 11,080; ansic: 1,958; xml: 467; makefile: 6
file content (42 lines) | stat: -rw-r--r-- 757 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
35
36
37
38
39
40
41
42
#! /usr/local/bin/ruby

require 'xml/parser'


XML1=<<EOF
<!--DOCTYPE test SYSTEM "hoge.dtd" [
<!ENTITY a "internal">
]-->
<test>&a;</test>
EOF

XML2=<<EOF
<!ENTITY a "external">
EOF

p = XML::Parser.new
if p.respond_to?(:useForeignDTD)
  p p.useForeignDTD(ARGV[0].to_i)
else
  puts "XML::Parser#useForeignDTD requires expat-1.95.5 or later"
end

p.setParamEntityParsing(1)
def p.startDoctypeDecl(name, sys, pub, internal)
  p(["startDoctypeDecl", name, sys, pub, internal])
end
def p.endDoctypeDecl()
  p(["endDoctypeDecl"])
end
def p.externalEntityRef(context, base, sys, pub)
  p(["externalEntityRef", context, base, sys, pub])
  extp = XML::Parser.new(self, context)
  extp.parse(XML2)
  extp.done
end

def p.character(data)
  p data
end

p.parse(XML1)