Can't write XML to stream outside of NetBeans

M

mark

I've been having a lot of trouble trying to create an XML file from a
DOM tree. My code works fine inside of netbeans, but I get lots of
erros when I try to run it independantly.

The error message I keep getting is

[java] java.lang.RuntimeException:
org.apache.xml.utils.WrappedRuntimeException: The output format must
have a '{http://xml.apache.org/xalan}content-handler' property!

Both Xerces and crimson are in my classpath, and I've tried using both
Java 1.5 and 1.4.2. Any ideas what I'm doing wrong?

This is the code I'm trying to write the file with:

public void writeXML(Document doc, OutputStream ostream)
{
try
{
//Format & write output
TransformerFactory tf = TransformerFactory.newInstance();
Transformer t = tf.newTransformer();

DOMSource ds = new DOMSource(doc);
StreamResult sr = new StreamResult(ostream);
t.transform(ds, sr);
}
catch (Exception e)
{
e.printStackTrace();
}
}

Mark McKay
 
H

hilz

I've been having a lot of trouble trying to create an XML file from a
DOM tree. My code works fine inside of netbeans, but I get lots of
erros when I try to run it independantly.

The error message I keep getting is

[java] java.lang.RuntimeException:
org.apache.xml.utils.WrappedRuntimeException: The output format must
have a '{http://xml.apache.org/xalan}content-handler' property!

Both Xerces and crimson are in my classpath, and I've tried using both
Java 1.5 and 1.4.2. Any ideas what I'm doing wrong?

This is the code I'm trying to write the file with:

public void writeXML(Document doc, OutputStream ostream)
{
try
{
//Format & write output
TransformerFactory tf = TransformerFactory.newInstance();
Transformer t = tf.newTransformer();

DOMSource ds = new DOMSource(doc);
StreamResult sr = new StreamResult(ostream);
t.transform(ds, sr);
}
catch (Exception e)
{
e.printStackTrace();
}
}

Mark McKay

I do the same and it works fine, in NetBeans and outside.
do you have those imports(maybe you don't need all of them, but those are
what i needed)?

import java.io.*;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
import org.w3c.dom.*;
import org.xml.sax.*;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,123
Latest member
Layne6498
Top