Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Referring to a local DTD in Java

Tags:

java

xml

dtd

sax

I have some XML that I'm parsing with a SAX parser in Java. It starts with this preamble:

<!DOCTYPE math 
    PUBLIC "-//W3C//DTD MathML 3.0//EN"
           "http://www.w3.org/Math/DTD/mathml3/mathml3.dtd">

How do I change this to use a local DTD?

I suppose I could do something like this:

<!DOCTYPE math 
    PUBLIC "-//W3C//DTD MathML 3.0//EN"
           "file:///c:/MathML/mathml3.dtd">

Not exactly like that, but something like that. However, I need the path to be independent of the user's system.

How do I use a local DTD with a path relative to the class path?

like image 317
Paul Reiners Avatar asked Jun 13 '11 14:06

Paul Reiners


1 Answers

When dealing with Web Apps, you can put the dtd in the lib folder and refer to it like:

<!DOCTYPE name PUBLIC 
    "-//CMP//DTD dtdName 1.0//EN"
        "/WEB-INF/lib/dtdName.dtd">
like image 123
Sully Avatar answered Sep 22 '22 21:09

Sully