[jdom-interest] NO DOC TYPE? There sure is!!!
Per Norrman
per.norrman at austers.se
Thu Oct 21 14:05:49 PDT 2004
Hi,
some comments:
1) Document#toString() does not generate the XML representation of the tree,
you have to use XMLOutputter#outputString().
2) If the only use of the JDOM Document is the input to a translation, then I
think your're better of translating directly from from the string using a
StreamSource. In this case you can also have the transformer generate XML
directly and control the DOCTYPE using an <xsl:output> element in
the stylesheet.
This is what happens in the JDOM case:
input -> JDOM tree -> SAX events -> xsl input tree -> transform -> output tree
-> SAX events -> JDOM tree --> XML string
compare this to:
input -> SAX events -> xsl input tree -> transform -> output tree -> XML string
Note that you cannot have the XSL translator creating a doctype node in the
resulting JDOM tree. Output processing is only applicable when the XSL processor
controls the XML/HTML/whatever output.
Hope this helps!
/pmn
gary.marshall at worldspan.com wrote:
> 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
>
> _______________________________________________
> To control your jdom-interest membership:
> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com
>
More information about the jdom-interest
mailing list