Error: null values displaying

Posted on 2006-04-23
Medium Priority
Last Modified: 2010-03-31
This program will take any xml file and show recursivly the depth of each tag
Problem is that the values are showing up as null when displayed

import org.w3c.dom.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import java.io.IOException;
import java.io.File;

public class XMLDisplay {
   //Global variables
  private static int depth = 0;
  private static Document document;
  private static DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
   //Main method, calls recursive function
  public static void main(String[] args) {
    try {
      DocumentBuilder builder = factory.newDocumentBuilder();
      document = builder.parse(new File(args[0]));
      listAll(document, depth);  
    } catch (SAXParseException spe) {
      // Error generated by the parser
      System.out.println("\n** Parsing error" + ", line " +
                         spe.getLineNumber() + ", uri " + spe.getSystemId());
      System.out.println("   " + spe.getMessage());
      // Use the contained exception, if any
      Exception x = spe;
      if (spe.getException() != null) {
        x = spe.getException();
    } catch (SAXException sxe) {
      // Error generated during parsing)
      Exception x = sxe;
      if (sxe.getException() != null) {
        x = sxe.getException();
    } catch (ParserConfigurationException pce) {
      // Parser with specified options can't be built
    } catch (IOException ioe) {
      // I/O error

public static void listAll(Node n, int depth)
    printName(n, depth);   // indent using level
    NodeList children = n.getChildNodes();
    for (int i=0; i < children.getLength(); i++) {
      Node child = children.item(i);
      listAll(child, depth+1);
  public static void printName(Node n, int depth) {
    for (int i = 0; i < depth; i ++)
      System.out.print("  ");
Question by:no158
  • 3
LVL 86

Expert Comment

ID: 16520470
listAll doesn't call println
LVL 86

Accepted Solution

CEHJ earned 2000 total points
ID: 16520481
Sorry - ignore that. You need to check the node and do


Author Comment

ID: 16520917
thanks again
LVL 86

Expert Comment

ID: 16523151

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month13 days, 14 hours left to enroll

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question