You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Bruno Faure <bf...@cosmosbay.com> on 2000/04/18 15:20:31 UTC

Generating DOM document

Hi,

I have a problem with my very first XML document generated with DOM :
when using toString() method, for having a look to the document
generated, it returns [#document: null], and I cannot find where I'm
wrong.
Could you give me a hand please ?

Here is my (simple) program :

import java.io.*;
import org.w3c.dom.*;
import org.apache.xerces.dom.*;

public class sampleDOM
{
    public static void main (String[] args) throws IOException,
DOMException
    {
     Writer out = new OutputStreamWriter(System.out);

     DocumentImpl xml_doc = new DocumentImpl();
     Element name = xml_doc.createElement("name");
     Element first = xml_doc.createElement("first");
     Element last = xml_doc.createElement("last");

      xml_doc.appendChild(name);
     name.appendChild(first);
     first.appendChild(xml_doc.createTextNode("\n Bruno \n"));
     name.appendChild(last);
     last.appendChild(xml_doc.createTextNode("\n FAURE \n"));

     out.write(xml_doc.toString());
     out.flush();
     System.exit(0);
    }
}

P.S : is there any other method to print the document on the standard
output than toString() method ?

Thanks in advance,

Bruno FAURE