[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
returned:
            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",

"C:/PortalDevelWork/WSPNewsPortlet/WebContent/wsp_News_portlets/scripts/newsrelease.dtd"
);
            oDoc.setDocType(theDocType);

//    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(

"C:/PortalDevelWork/WSPNewsPortlet/WebContent/wsp_News_portlets/style/templates/TestTempl008.xsl"
));

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

//    Dump the result to the browser:
            %><%=outDoc%><%


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
      id CDATA #REQUIRED
>

Here is the beginning of the "strXMLReturn" string:

  <newsreleases usercountryid="382" userlanguageid="1">
     <news id="927">
       <name>New Helpdesk Number for Switzerland</name>
       <global>F</global>
       <startdate>03/12/2004</startdate>
       <enddate>12/31/2004</enddate>
       <language id="1635" langid="1" langcode="english">
          <publishedversion>5410</publishedversion>
       </language>
       <version id="5410" VersionNewsLangid="1635">
          <Versionlanguage>1</Versionlanguage>
          <publishdate>03/12/2004</publishdate>
          <displayname>New Helpdesk Number for Switzerland in G/F/I/E</
displayname>
          <abstract> </abstract>
       </version>
     </news>

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
results.

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



More information about the jdom-interest mailing list