Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import org.w3c.dom.*;
import java.io.File;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

public class Main {
    public static void getXMLContent(String filePath) {
        try {
            File f = new File(filePath);
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = factory.newDocumentBuilder();
            org.w3c.dom.Document doc = builder.parse(f);
            NodeList nodes_1 = doc.getChildNodes();
            for (int i = 0; i < nodes_1.getLength(); i++) {
                org.w3c.dom.Node nodes_2 = nodes_1.item(i);
                NodeList nodes_3 = nodes_2.getChildNodes();
                for (int j = 0; j < nodes_3.getLength(); j++) {
                    org.w3c.dom.Node node = nodes_3.item(j);
                    NodeList xmlMeta = node.getChildNodes();
                    for (int k = 0; k < xmlMeta.getLength(); k++) {
                        //                  value = xmlMeta.item(k).getNodeValue();
                        System.out.println(xmlMeta.item(k).getNodeName() + ":" + xmlMeta.item(k).getNodeValue());
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}