Hello again,
I asked this before but I didn't get any answers. So i'll ask again
Now with example. The versions are
ruby 1.6.5
xmlparser 0.6.1
expat 1.95.2
The below example should generate error, because there is #REQUIRED in dtd,
and not to happily print
xmltest output: bar is >bar< and baz is >baz
--- xmtest.rb ----
require 'xmlparser'
class Foo < XML::Parser
attr_reader :bar, :baz
def startElement(name, attr)
if name == "foo"
@bar = attr['bar']
@baz = attr['baz']
end
end
def endElement(name)
end
def externalEntityRef(context, base, systemId, publicId)
e = Foo.new(self, context)
e.parse(open(systemId).read)
e.done
end
end
f = Foo.new
if f.respond_to?(:setParamEntityParsing)
f.setParamEntityParsing(XML::Parser::PARAM_ENTITY_PARSING_UNLESS_STANDALONE)
end
begin
f.parse(File.open("foobar.xml").read)
rescue XML::ParserError
puts "#{$!} in line #{f.line}\n"
exit
end
puts "bar is >#{f.bar}< and baz is >#{f.baz}<"
-------------------
--------foobar.xml---------------
<!ELEMENT foobar (foo, barbaz)>
<!ELEMENT foo EMPTY>
<!ATTLIST foo
bar CDATA #REQUIRED
foo CDATA #REQUIRED
baz CDATA "baz"
>
<!ELEMENT barbaz EMPTY>
<!ATTLIST barbaz
barfoo CDATA #REQUIRED
>
---------------
--- foobar.dtd---------
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<!DOCTYPE foobar SYSTEM "foobar.dtd">
<foobar>
<foo bar="bar"/>
</foobar>