Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

document.getDocumentElement returns null

843834Oct 6 2004 — edited Oct 8 2004
Hi!

I've installed the new Java 1.5 and found a problem with one of my programs. I tested it and found out, that the problem is the Default Java XML Parser. Here is an example:

import java.io.File;

import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
public class Test {
  public static void main(String[] args) {
    String countryPath = "countries.xml";
    try {
      Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new File(countryPath));
      System.out.println(document.getDocumentElement());
    } catch (Exception exception) {
      exception.printStackTrace();
    }
  }
}
If I compile (simple javac Test.java) and run the program with Java 1.5 under Windows XP/SP2 or Linux (SuSE 9.0) I always get null in System.out. If I do the same with Java 1.4 I get the content of the XML file. There is no exception. I tried also an validating enabled Parser with my own ErrorHandler . Its the same.

Has someone an idea, why this happens? I had months ago a similar problem with Java 1.4 and did not find a solution for this strange behavior.... It's very bad to find the error, if there is no message.

The XML file contains the following:
<?xml version="1.0"?>
<countries>
  <country>
    <de>Deutschland</de>
    <en>Germany</en>
  </country>
</countries>
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 5 2004
Added on Oct 6 2004
7 comments
1,141 views