# Rexml dtd parser

**URL:** <https://www.ruby-forum.com/t/rexml-dtd-parser/106330>\
**Category:** Ruby\
**Created:** [June 8, 2007, 5:19pm UTC](https://www.ruby-forum.com/t/rexml-dtd-parser/106330 "2007-06-08T17:19:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![shadowcipher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/45deac/32.png) [@shadowcipher](https://www.ruby-forum.com/u/shadowcipher)\
**Post date:** [June 8, 2007, 5:19pm UTC](https://www.ruby-forum.com/t/rexml-dtd-parser/106330/1 "2007-06-08T17:19:42Z")

</div>

I seem to have some personal confusion with how to correctly utilize the  
rexml/dtd library. I am using ruby version 1.8.6 and when I orginally  
tried  
to use the code I received some unknown method errors. I modified the  
code  
in the case statement contained in dtd.rb from the notation  
when ElementDecl.PATTERN\_RE

to when ElementDecl::PATTERN\_RE

I no longer received these errors. However, I am now receiving the  
following error.

uninitialized constant REXML::DTD::EntityDecl::PATTERN\_RE

When I look at the code in entitydecl.rb I see the following line;

md = source.match( PATTERN\_RE, true )

However PATTERN\_RE is not declared or intialized in the entitydecl.rb  
file.  
Am I implementing the library wrong or is this code still bugged?

Any help is much appreciated.

Below is a snapshot of how I am trying to use this library.

#!/usr/bin/ruby -dw

require “rexml/dtd/dtd”  
require “pathname”

dtdarg = ARGV[0]

def dtdparse(dtdfile)  
path = Pathname::new(dtdfile)  
if path.relative? then  
dtdfile = File::expand\_path(dtdfile)  
end  
dtddata = REXML::DTD::Parser::parse(dtdfile)  
puts dtddata  
end

dtdparse(dtdarg)

---

<div class="post-metadata">

**Author:** ![shadowcipher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/45deac/32.png) [@shadowcipher](https://www.ruby-forum.com/u/shadowcipher)\
**Post date:** [August 19, 2008, 4:14pm UTC](https://www.ruby-forum.com/t/rexml-dtd-parser/106330/2 "2008-08-19T16:14:18Z")

</div>

I have had the same problems using the dtd parsing section of rexml. I  
got past all the errors only to find that it’s not really parsing all  
parts of the dtd. The parse\_helper isn’t even written quite correctly as  
a parser – it ends up catching only the ElementDeclarations, then  
possibly a few things after the last ElementDeclaration. Anyway, it  
looks like it’s not a fully-written feature of rexml yet. I decided  
since I need it I’ll have to write my own ruby DTD-parser. I might be  
putting it on github as a gem (check back at [dcparker (Daniel Parker) · GitHub](http://github.com/dcparker)  
later).

By the way, does ANYBODY out there know of a real dtd parser in ruby? I  
need one that will parse a dtd and actually understand the lists of  
attributes and child elements and such. (If none show up, watch for  
mine, I probably won’t post it to this list, but it’ll be on github.)

~Daniel

Nathan T. wrote:

> I seem to have some personal confusion with how to correctly utilize the  
> rexml/dtd library. I am using ruby version 1.8.6 and when I orginally  
> tried  
> to use the code I received some unknown method errors. I modified the  
> code  
> in the case statement contained in dtd.rb from the notation  
> when ElementDecl.PATTERN\_RE
> 
> to when ElementDecl::PATTERN\_RE
> 
> I no longer received these errors. However, I am now receiving the  
> following error.
> 
> uninitialized constant REXML::DTD::EntityDecl::PATTERN\_RE
> 
> When I look at the code in entitydecl.rb I see the following line;
> 
> md = source.match( PATTERN\_RE, true )
> 
> However PATTERN\_RE is not declared or intialized in the entitydecl.rb  
> file.  
> Am I implementing the library wrong or is this code still bugged?
> 
> Any help is much appreciated.
> 
> Below is a snapshot of how I am trying to use this library.
> 
> #!/usr/bin/ruby -dw
> 
> require “rexml/dtd/dtd”  
> require “pathname”
> 
> dtdarg = ARGV[0]
> 
> def dtdparse(dtdfile)  
> path = Pathname::new(dtdfile)  
> if path.relative? then  
> dtdfile = File::expand\_path(dtdfile)  
> end  
> dtddata = REXML::DTD::Parser::parse(dtdfile)  
> puts dtddata  
> end
> 
> dtdparse(dtdarg)
