[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
	// A JDOM SAXBuilder() 
	private SAXBuilder builder;
	public ReadGroupServicesXml () {
		builder = new
	} // End of Constructor

    private Document readXmlDocument() {
        // A string to hold xmlfilelocation
		String xmlFileLocation = null;	
		// JDOM Class
		Document xmlDocument = null;    
        try {
            xmlFileLocation = GRPSVCS_XMLFILENAME;
			//xmlDocument = builder.build(new
			// use InputStreamReader to convert input
non-unicode characters to unicode characters
			FileInputStream fis =new FileInputStream(new
            InputStreamReader isr = new
InputStreamReader(fis, "UTF-8");
            BufferedReader reader = new
            xmlDocument = builder.build(reader);
            return xmlDocument;
        } catch (Exception re) {
System.err.println("readXmlDocument Method: " +
            return null;
    } // end of readXmlDocument()

    public static void main(String[] args) {
ReadGroupServicesXml read = new
Document doc = read.readXmlDocument();
    } // end of Main method

} // end of ReadGroupServicesXml Class

Do You Yahoo!?
Yahoo! Y! Pages - Search or browse for business listings.

More information about the jdom-interest mailing list