Hi There,
This is my first posting to XML-Dev. Great mailing
list. I have been using the IBM XML4J Parser (v2.0.9) class for just a short
while. The client has requested that we inline the DTD's instead of making them
external.
I resorted to the following sample
code,
Parser p
= new Parser(getDefaultDTDPath(), this,
null); DTD aDTD = null
; try
{
BufferedReader b = new BufferedReader(new FileReader("SampleDTD.dtd"))
; aDTD =
p.readDTDStream(b)
;
b.close() ; } catch (IOException
ex) { }
aDTD.setName("CustomerDataResponse")
; StringWriter aWriter = new
StringWriter(); try
{
aDTD.print(aWriter) ; } catch
(IOException ex) {}
System.out.println(aWriter.toString()) ;
Used on the following XML file (with inline
DTD),
<?xml version="1.0"
encoding="UTF-8"?> <!DOCTYPE CustomerDataResponse [ <!ELEMENT
CustomerDataResponse (pass|fail)> <!ATTLIST CustomerDataResponse
accountNumber CDATA #REQUIRED> <!ELEMENT pass
(question*)> <!ELEMENT question (#PCDATA)> <!ATTLIST question
questionId ID
#REQUIRED
answers CDATA #IMPLIED> <!ELEMENT fail (reason)> <!ELEMENT
reason (#PCDATA)> ]>
Produces the results,
<!DOCTYPE CustomerDataResponse
[ <!ATTLIST CustomerDataResponse accountNumber CDATA
#REQUIRED> <!ELEMENT pass (question*)> <!ELEMENT question
(#PCDATA)> <!ATTLIST question questionId ID
#REQUIRED
answers CDATA #IMPLIED> <!ELEMENT fail (reason)> <!ELEMENT
reason (#PCDATA)> ]>
Note that there is no line,
<!ELEMENT CustomerDataResponse
(pass|fail)>
Which totally invalidates the DTD.
Now the interesting thing is that if I duplicate
this line in the original DTD, i.e.,
<?xml version="1.0"
encoding="UTF-8"?> <!DOCTYPE CustomerDataResponse [ <!ELEMENT
CustomerDataResponse (pass|fail)> <!ELEMENT CustomerDataResponse
(pass|fail)> <!ATTLIST CustomerDataResponse accountNumber CDATA
#REQUIRED> <!ELEMENT pass (question*)> <!ELEMENT question
(#PCDATA)> <!ATTLIST question questionId ID
#REQUIRED
answers CDATA #IMPLIED> <!ELEMENT fail (reason)> <!ELEMENT
reason (#PCDATA)> ]>
It produces the desired results!! Anyone found similiar results? I can't think of anything that
I'm doing wrong.
Thanks,
|