File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes How to define a DTD in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "How to define a DTD in java" Watch "How to define a DTD in java" New topic
Author

How to define a DTD in java

Maha Hassan
Ranch Hand

Joined: Aug 02, 2005
Posts: 133
Dear all,

I want to define a dtd in java to be able to trasverse it . I mean.. i have a String representation of a dtd and i want to construct a dtd object using this string represntation to be able to use methods like getelement() etc.


Thanks.

Maha
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

When I do a web search for the keywords "java dtd parser" I get links to several sites that claim to have DTD parsers written in Java -- which is what you are looking for. Check them out.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42919
    
  68
I quite like DTDParser. I remember that it was quite easy to add a few constructors and methods that I needed, but it's quite full-featured as it is.
Maha Hassan
Ranch Hand

Joined: Aug 02, 2005
Posts: 133
DTD parser sounds good but how to install it
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

Usually the way to "install" Java infrastructure tools like this is to take the jar file they come in and put it in your classpath. Of course whatever product you have there may come with installation instructions. These tend to be in files named "Readme" or something like that. Just look around at what you have there.
Maha Hassan
Ranch Hand

Joined: Aug 02, 2005
Posts: 133
Hi,
I tried to run the Tokenize.java againt the follwong dtd
<!DOCTYPE TVSCHEDULE [<!ELEMENT TVSCHEDULE (CHANNEL+)>
<!ELEMENT CHANNEL (BANNER,DAY+)>
<!ELEMENT BANNER (#PCDATA)>
<!ELEMENT DAY (DATE,(HOLIDAY|PROGRAMSLOT+)+)>
<!ELEMENT HOLIDAY (#PCDATA)>
<!ELEMENT DATE (#PCDATA)>
<!ELEMENT PROGRAMSLOT (TIME,TITLE,DESCRIPTION?)>
<!ELEMENT TIME (#PCDATA)>
<!ELEMENT TITLE (#PCDATA)>
<!ELEMENT DESCRIPTION (#PCDATA)>

<!ATTLIST TVSCHEDULE NAME CDATA #REQUIRED>
<!ATTLIST CHANNEL CHAN CDATA #REQUIRED>
<!ATTLIST PROGRAMSLOT VTR CDATA #IMPLIED>
<!ATTLIST TITLE RATING CDATA #IMPLIED>
<!ATTLIST TITLE LANGUAGE CDATA #IMPLIED>

]>

but i get an error saying "{com.wutka.dtd.DTDPARSEEXCEPTION: At line 1,cloumn 23 :illegal charachter in input stream: 91"

so what is that.. i tried removing the [< in the start and at the end but it does not know th root elemnt this way.

thanks

[ July 13, 2006: Message edited by: Maha Hassan ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42919
    
  68
DTDParser deals with free-standing DTDs, not DOCTYPE declarations as they are used in XML files. If you remove the "<!DOCTYPE TVSCHEDULE [" at the beginning fo the file, and the "]>" at the end, it'll work fine.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to define a DTD in java