[jdom-interest] Please help me
Bansidhar Giri
bansiauction at yahoo.com.sg
Wed Sep 12 05:13:16 PDT 2001
Can Someone help me in solving this. I have an xml
file which contains both english and chinese
characters. I am trying to build a Document object
from that. i use UTF8 character encoding while
building the document object using
SAXBuilder.build(InoutStream)...but somehow i keep
getting this error message.
readXmlDocument Method: org.jdom.JDOMException: Error
on line 1: The root element is required in a
well-formed document.
Here is my program...
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import org.jdom.input.SAXBuilder;
import org.jdom.Document;
import org.jdom.output.XMLOutputter;
public class ReadGroupServicesXml {
// xml file to be converted to a java object
private final static String
GRPSVCS_XMLFILENAME="GroupServices.xml";
// A JDOM SAXBuilder()
private SAXBuilder builder;
public ReadGroupServicesXml () {
builder = new
SAXBuilder("org.apache.xerces.parsers.SAXParser",false);
} // End of Constructor
private Document readXmlDocument() {
// A string to hold xmlfilelocation
String xmlFileLocation = null;
// JDOM Class
Document xmlDocument = null;
try {
xmlFileLocation = GRPSVCS_XMLFILENAME;
System.out.println("readXmlDocument:xmlFileLocation:
"+xmlFileLocation);
//xmlDocument = builder.build(new
File(xmlFileLocation));
// use InputStreamReader to convert input
non-unicode characters to unicode characters
FileInputStream fis =new FileInputStream(new
File(xmlFileLocation));
InputStreamReader isr = new
InputStreamReader(fis, "UTF-8");
BufferedReader reader = new
BufferedReader(isr);
xmlDocument = builder.build(reader);
return xmlDocument;
} catch (Exception re) {
System.err.println("readXmlDocument Method: " +
re.toString());
return null;
}
} // end of readXmlDocument()
public static void main(String[] args) {
ReadGroupServicesXml read = new
ReadGroupServicesXml();
Document doc = read.readXmlDocument();
} // end of Main method
} // end of ReadGroupServicesXml Class
__________________________________________________
Do You Yahoo!?
Yahoo! Y! Pages - Search or browse for business listings.
http://yp.yahoo.com.sg/
More information about the jdom-interest
mailing list