[jdom-interest] NO DOC TYPE? There sure is!!!

gary.marshall at worldspan.com gary.marshall at worldspan.com
Thu Oct 21 04:10:14 PDT 2004

In a JSP file I am writing using IBM's Websphere Studio Site Developer IDE,
I am using JDOM with a Document object created from an XML string and a XSL
file to create formatted output to render to the client browser.

Heres' the code:

            SAXBuilder oBuilder = new SAXBuilder();
            ...... strXMLReturn string primed here......
//  Create a StringReader class to read the string containingthe XML
            StringReader strReader = new StringReader(strXMLReturn);
            Document oDoc = oBuilder.build(strReader);

//          Set the DocType using a DTD file the exists on the local
machine directory:
            DocType theDocType = new DocType("newsreleases",


//    Set up the XSLT stylesheet for use with Xalan-J (the Java version of
the Apache Xalan processor)
          Transformer transformer = TransformerFactory.newInstance()
            .newTransformer(new StreamSource(


//    Do the transform!!!:
            JDOMResult output = new JDOMResult();
            transformer.transform(new JDOMSource(oDoc),output);
            Document outDoc = output.getDocument();

//    Dump the result to the browser:

Here is a snippet of the DTD file:

      <!ELEMENT newsreleases (news+)>
            <!ATTLIST newsreleases
            usercountryid           CDATA #IMPLIED
            userlanguageid          CDATA #REQUIRED
      <!ELEMENT news (name, global, startdate, enddate, assoccountry*,
language*, version*)>
      <!ATTLIST news

Here is the beginning of the "strXMLReturn" string:

  <newsreleases usercountryid="382" userlanguageid="1">
     <news id="927">
       <name>New Helpdesk Number for Switzerland</name>
       <language id="1635" langid="1" langcode="english">
       <version id="5410" VersionNewsLangid="1635">
          <displayname>New Helpdesk Number for Switzerland in G/F/I/E</
          <abstract> </abstract>

So, I have set the DOCTYPE of the document I sent into the transformer.
The result that gets sent back to the browser is:

                  [Document: No DOCTYPE declaration, Root is [Element: ]]

Thats it.

Now I have also tried to put all the DOCTYPE information (all of the code
in the DTD file) inside of and at the top of an XML file, before all of the
XML nodes and fed that XML file into the transformer and got the same

Any ideas as to what I am missing?
Thanks to all for your time and assistance

More information about the jdom-interest mailing list