You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by js...@odshp.com on 2001/10/17 00:36:17 UTC
DOM Output?
I'm using Tomcat and Cocoon together, and I have the xerces jar file
in tomcat/lib. The following fragment works great in a servlet...
public void output() {
try {
DOMImplementation imp = new DOMImplementationImpl();
Document doc = imp.createDocument(null, "page", null);
Element root = doc.getDocumentElement();
Element title = doc.createElement("title");
root.appendChild(title);
}
catch(Exception e) {
out.print(e.toString());
}
}
Once my document is build, how do I output formatted XML? For the
life of me I can't find an example of building and XML doc with xerces
and outputting the formated XML.
One example I found uses this:
XmlDocument doc = new XmlDocument();
.... Build doc....
doc.write(out);
where "out" is a OutputStreamWriter. This would be great! Except
that I get a class def not found for XmlDocument (I guess it's in
tomcat's xml.jar?)
I'm doing all this so that cocoon can receive XML from a servlet and
format it. And I'm doing that because JConnect (Sybase JDBC) doesn't
want to work from a Cocoon XML page (although it works fine in my
servlets).
Everything else works. If I simply print out the XML "by hand" in the
servlet, Cocoon applies my style sheet perfectly! All I need to know
is how to output the XML.
PS - the XmlDocument method works fine in my Visual Age environment
where I have Tomcat source loaded and running. I thought I had my
solution until I found that that class can't be found in the
production install.
--
Jeff Sexton
ODS Health Plans
jsexton@odshp.com
---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>
To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>
RE: DOM Output?
Posted by Karl Øie <ka...@gan.no>.
try something like this:
try {
org.apache.xalan.serialize.SerializerToXML serial = new
org.apache.xalan.serialize.SerializerToXML();
java.util.Properties props = new Properties();
props.setProperty( javax.xml.transform.OutputKeys.METHOD, "xml" );
props.setProperty( javax.xml.transform.OutputKeys.ENCODING, "ISO-8859-1" );
props.setProperty( javax.xml.transform.OutputKeys.MEDIA_TYPE,
out.getEncoding() );
props.setProperty( javax.xml.transform.OutputKeys.DOCTYPE_PUBLIC,
doc.getDoctype().getPublicId() );
props.setProperty( javax.xml.transform.OutputKeys.DOCTYPE_SYSTEM,
doc.getDoctype().getSystemId() );
props.setProperty( javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION,
"no" );
props.setProperty( javax.xml.transform.OutputKeys.INDENT, "no" );
props.setProperty( javax.xml.transform.OutputKeys.STANDALONE, "no" );
props.setProperty( javax.xml.transform.OutputKeys.CDATA_SECTION_ELEMENTS,
"" );
serial.init( out, props );
serial.asDOMSerializer();
serial.serialize( (Node)doc );
}
catch(IOException e) {
System.err.println( "serializer : "+e.getMessage() );
}
where out is a Writer of some sort. this requires xalan though....
mvh karl øie
-----Original Message-----
From: jsexton@ods1.odshp.com [mailto:jsexton@ods1.odshp.com]On Behalf Of
jsexton@odshp.com
Sent: 17. oktober 2001 00:36
To: cocoon-users@xml.apache.org
Subject: DOM Output?
I'm using Tomcat and Cocoon together, and I have the xerces jar file
in tomcat/lib. The following fragment works great in a servlet...
public void output() {
try {
DOMImplementation imp = new DOMImplementationImpl();
Document doc = imp.createDocument(null, "page", null);
Element root = doc.getDocumentElement();
Element title = doc.createElement("title");
root.appendChild(title);
}
catch(Exception e) {
out.print(e.toString());
}
}
Once my document is build, how do I output formatted XML? For the
life of me I can't find an example of building and XML doc with xerces
and outputting the formated XML.
One example I found uses this:
XmlDocument doc = new XmlDocument();
.... Build doc....
doc.write(out);
where "out" is a OutputStreamWriter. This would be great! Except
that I get a class def not found for XmlDocument (I guess it's in
tomcat's xml.jar?)
I'm doing all this so that cocoon can receive XML from a servlet and
format it. And I'm doing that because JConnect (Sybase JDBC) doesn't
want to work from a Cocoon XML page (although it works fine in my
servlets).
Everything else works. If I simply print out the XML "by hand" in the
servlet, Cocoon applies my style sheet perfectly! All I need to know
is how to output the XML.
PS - the XmlDocument method works fine in my Visual Age environment
where I have Tomcat source loaded and running. I thought I had my
solution until I found that that class can't be found in the
production install.
--
Jeff Sexton
ODS Health Plans
jsexton@odshp.com
---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>
To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>
---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>
To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>