carp __ wrote:
Hello Rubyists,
I’d like to have a custom made XML configuration file parsed with a
custom made DTD file. However, the documentation at
http://www.ruby-doc.org/stdlib/libdoc/rexml/rdoc/classes/REXML/DTD.html
doesn’t help me a lot. Is there anybody who could paste a simple 4-liner
example scenario about how this would be done?
RexML can’t do external DTDs, and the author told me it won’t ever,
as he believes that the syntax is too evil to even contemplate.
When I needed to do it, on Windows systems having cygwin installed,
I just opened the XML file using a pipe from xmllint, which was
launched with the right parameters to make it expand the entities
from an external DTD. The main awkwardness comes from the fact that
xmllint looks for unqualified DTD files in the same directory as
the XML file, so you need to extract the directory pathname from
the file’s basename and cd to that directory first:
cmd = “sh -c ‘cd #{dir}; xmllint --loaddtd --noent - <#{base}’”
infile = popen(cmd)
Best of luck.
Clifford H…