[jdom-interest] Please help me

Jason Hunter jhunter at collab.net
Thu Sep 13 11:40:08 PDT 2001


It'd help if you included the xml file.  Sounds like it's missing a root
element.

-jh-

Bansidhar Giri wrote:
> 
> 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/
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com



More information about the jdom-interest mailing list