Get XML Declaration To Appear in XML

I have a program that takes a text file and converts it to XML. I dont know how to get the XML declaration to appear at the top of th XML.

Heres what I got:

import java.io.BufferedReader;

import java.io.File;

import java.io.FileWriter;

import java.io.FileReader;

import java.io.IOException;

import org.jdom.Element;

import org.jdom.output.XMLOutputter;

publicclass XML_builder{

public XML_builder(){}

publicstaticvoid main(String[] args){

testBuildXML();

}

privatestaticvoid testBuildXML(){

try{

String textFile ="P://Useful Docs/Programming/Java/Automated Texting/Automated Texting/phoneNumbers.txt";

String XMLFile ="P://Useful Docs/Programming/Java/Automated Texting/Automated Texting/phoneNumbers.xml";

File text =new File(textFile);

FileReader reader=new FileReader(text);

BufferedReader buffer=new BufferedReader(reader);

String temp="";

int x=0;

Element element =new Element("phone_numbers");

while ((temp = buffer.readLine())!=null){

Element child_node =new Element("number_"+x);

System.out.println(temp);

child_node.addContent(temp);

x++;

element.addContent(child_node);

}

FileWriter writer =new java.io.FileWriter(XMLFile);

XMLOutputter xmloutputter =new XMLOutputter();

xmloutputter.output(element, writer);

}

catch (IOException exception){

System.out.println(exception);

}

}

}

Message was edited by:

paul_carron

[3007 byte] By [paul_carrona] at [2007-11-27 9:15:25]
# 1
you are printing an element. Create a Document, then output it using the outputter.Document doc = new Document(element);xmloutputter.output(doc, writer);~TimMessage was edited by: SomeoneElse
SomeoneElsea at 2007-7-12 22:04:29 > top of Java-index,Java Essentials,New To Java...
# 2
Cheers. Sorted now.
paul_carrona at 2007-7-12 22:04:29 > top of Java-index,Java Essentials,New To Java...