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

