Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
// publish, distribute, sublicense, and/or sell copies of the Software, 

import java.util.Vector;

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Main {
    /**
     * Extract included filenames in the XML document, assuming that filenames are
     * provided with the attribute "href".
     * 
     * @param xmlDocument the XML document
     * @return the filenames to include
     */
    private static Vector<String> extractIncludedFiles(Document xmlDocument) {

        Vector<String> includedFiles = new Vector<String>();

        NodeList top = xmlDocument.getChildNodes();
        for (int i = 0; i < top.getLength(); i++) {
            Node topNode = top.item(i);
            NodeList firstElements = topNode.getChildNodes();
            for (int j = 0; j < firstElements.getLength(); j++) {
                Node midNode = firstElements.item(j);
                for (int k = 0; k < midNode.getChildNodes().getLength(); k++) {
                    Node node = midNode.getChildNodes().item(k);
                    if (node.hasAttributes() && node.getAttributes().getNamedItem("href") != null) {
                        String fileName = node.getAttributes().getNamedItem("href").getNodeValue();
                        includedFiles.add(fileName);
                    }
                }

            }
        }
        return includedFiles;
    }
}