Document root element is missing
3 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Tuesday, November 25, 2003 08:29 AM

Hi. I have a problem with XML. Occur this exception: org.xml.sax.SAXParseException: Document root element is missing. My file (dep.xml) is: <?xml version="1.0"?> classdep c:/Documents and Settings/lad/bci/Depend/temp/classdep/com/jpl/ treewalk c:/Documents and Settings/lad/bci/Depend/temp/classdep/com/jpl/ And my code is: ... DocumentBuilderFactory dbfBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); Document doc = do   More>>

Hi.

I have a problem with XML. Occur this exception:


org.xml.sax.SAXParseException: Document root element is missing.

My file (dep.xml) is:



<?xml version="1.0"?>





classdep

c:/Documents and Settings/lad/bci/Depend/temp/classdep/com/jpl/





treewalk

c:/Documents and Settings/lad/bci/Depend/temp/classdep/com/jpl/







And my code is:



...

DocumentBuilderFactory dbfBuilderFactory = DocumentBuilderFactory.newInstance();

DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();

Document doc = docBuilder.parse (new File("C:\eclipse\workspace\classdep\dep.xml"));

Element root = doc.createElement("root");

doc.appendChild(root);

doc.getDocumentElement().normalize();

NodeList listOfTablas = doc.getElementsByTagName("tablas");

int totalTablas = listOfTablas.getLength();

System.out.println("Total de tablas : " + totalTablas);


...

...



What's wrong? Help!



Luiz Augusto

   <<Less

Re: Document root element is missing

Posted By:   Michael_Eastwood  
Posted On:   Thursday, February 5, 2004 08:39 PM

I know it's a little late in the piece, but it is probably a parser version problem.



I downloaded the Java Web Services Developer pack from Sun, which has its own xalan.jar (containing the crimson SAX parser) dated Jan 2001. This was my default. I changed my classpath to use another one I had that came with the Jetty server, and the error disappeared.



Lesson: beware the JWSDP. Get the latest parsers from apache.org.

Re: Document root element is missing

Posted By:   krishnakanth_Rengarajan  
Posted On:   Wednesday, November 26, 2003 02:05 AM

It works for me,Follows my Xml and java file.
dep.xml







classdep

c:/Documents and Settings/lad/bci/Depend/temp/classdep/com/jpl/





treewalk

c:/Documents and Settings/lad/bci/Depend/temp/classdep/com/jpl/






XMLTest.java


import javax.xml.parsers.*;

import org.w3c.dom.*;

import java.io.*;



public class XMLTest

{

public static void main(String str[])

{

try

{

DocumentBuilderFactory dbfBuilderFactory = DocumentBuilderFactory.newInstance();

DocumentBuilder docBuilder = dbfBuilderFactory.newDocumentBuilder();

Document doc = docBuilder.parse (new File("C:\eclipse\workspace\classdep\dep.xml"));

Element root = doc.createElement("root");
doc.appendChild(root);

doc.getDocumentElement().normalize();

NodeList listOfTablas = doc.getElementsByTagName("tablas");

int totalTablas = listOfTablas.getLength();

System.out.println("Total de tablas : " + totalTablas);



}catch(Exception e)

{

System.out.println("Error");

}

}

}


I works fine and gives me the following output:

Total de tablas : 2

Re: Document root element is missing

Posted By:   Michael_Wax  
Posted On:   Tuesday, November 25, 2003 09:48 AM

Try renaming your document to root.xml, or create a DTD and add a DOCTYPE entry of the form:


About | Sitemap | Contact