debug XML Document - Java XML

Java examples for XML:DOM Document

Description

debug XML Document

Demo Code


//package com.java2s;

import org.w3c.dom.*;

public class Main {
    public static void debugDocument(Document doc) {
        System.out.println("Document Summary");
        System.out.println("  obj = " + ((Object) doc).toString());
        System.out.println("  localName = '" + doc.getLocalName() + "'");
        System.out.println("  namespaceURI = '" + doc.getNamespaceURI()
                + "'");
        System.out.println("  documentElement = "
                + doc.getDocumentElement());
        System.out.println("  implementation = " + doc.getImplementation());
        System.out.println("  nodeType = " + doc.getNodeType());
        System.out.println("  ownerDocument = " + doc.getOwnerDocument());

        NodeList nl = doc.getChildNodes();
        int size = nl.getLength();
        for (int i = 0; i < size; i++) {
            System.out.println("    : " + nl.item(i).getLocalName());

            Node curNode = nl.item(i);
            System.out.println("-------------");
            System.out.println(curNode.getLocalName());
            System.out.println("namespace URI: '"
                    + curNode.getNamespaceURI() + "'");
            System.out.println(curNode.getNodeType());
            System.out.println(curNode.hasChildNodes());
            System.out.println("-------------");

            NodeList nl2 = nl.item(i).getChildNodes();
            for (int j = 0; j < nl2.getLength(); j++) {
                System.out.println("    ... " + nl2.item(j).getLocalName());
            }//from   w ww  .j  av  a 2s. c  o m
        }

    }
}

Related Tutorials