From: Ville Mattila Date: 2002-03-21T00:02:30+09:00 Subject: Q: Xmlparser and DTDs 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--------------- --------------- --- foobar.dtd---------