Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to define a DTD in java

 
Maha Hassan
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DTD parser sounds good but how to install it
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic