REXML + DTD example

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?

Thanks a lot in advance

-carp

On 24.04.2007 14:42, carp __ wrote:

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?

Did you look at
http://www.germane-software.com/software/rexml/docs/tutorial.html
reachable from http://www.germane-software.com/software/rexml/ ?

robert

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…

carp __ wrote:

Thanks for that hint, Clifford.

You’re welcome. It took a bit of headscratching before
I convinced myself we had to go that way, but seeing
that we had a type of XML file that needed to be expanded
with two different sets of entities (for code generation
and for documentation generation), it was only pragmatic.

Clifford.

Clifford H. wrote:

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)

Thanks for that hint, Clifford. I did it with xmllint now - a bit ugly
as it makes the script less portable, but well … better than nothing I
guess. Thanks again!

-carp

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs