REXML + DTD example

R

Robert Klemme

C

Clifford Heath

carp said:
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 Heath.
 
C

carp __

Clifford said:
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
 
C

Clifford Heath

carp said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top