Can't write XML to stream outside of NetBeans

Discussion in 'Java' started by mark@kitfox.com, Dec 17, 2004.

  1. Guest

    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
    , Dec 17, 2004
    #1
    1. Advertising

  2. hilz Guest

    <> wrote in message
    news:...
    > 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.*;
    hilz, Dec 17, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Pimousse
    Replies:
    2
    Views:
    3,619
    Roedy Green
    Apr 21, 2004
  2. Rick T.
    Replies:
    1
    Views:
    382
    Andrew Thompson
    Nov 30, 2004
  3. Ilias Lazaridis
    Replies:
    0
    Views:
    896
    Ilias Lazaridis
    Dec 12, 2004
  4. shihr
    Replies:
    1
    Views:
    382
    shihr
    Jul 26, 2009
  5. Krzysztof Poc

    outside type, outside function

    Krzysztof Poc, Feb 3, 2012, in forum: C++
    Replies:
    1
    Views:
    274
    Victor Bazarov
    Feb 7, 2012
Loading...

Share This Page