Error: null values displaying

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();
      }
     
      x.printStackTrace();
    } catch (SAXException sxe) {
      // Error generated during parsing)
      Exception x = sxe;
     
      if (sxe.getException() != null) {
        x = sxe.getException();
      }
     
      x.printStackTrace();
    } catch (ParserConfigurationException pce) {
      // Parser with specified options can't be built
      pce.printStackTrace();
    } catch (IOException ioe) {
      // I/O error
      ioe.printStackTrace();
    }
  }

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("  ");
    System.out.println(n.getLocalName());
  }
}
no158Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
listAll doesn't call println
0
CEHJCommented:
Sorry - ignore that. You need to check the node and do

System.out.println(n.getNodeName());
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
no158Author Commented:
thanks again
0
CEHJCommented:
:-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.