Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * XML Sequences for mission critical IT procedures
 *
 * Copyright  2004-2010 Operational Dynamics Consulting, Pty Ltd
 *
 * The code in this file, and the program it is a part of, is made available
 * to you by its authors as open source software: you can redistribute it
 * and/or modify it under the terms of the GNU General Public License version
 * 2 ("GPL") as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GPL for more details.
 *
 * You should have received a copy of the GPL along with this program. If not,
 * see http://www.gnu.org/licenses/. The authors of this program may be
 * contacted through http://research.operationaldynamics.com/projects/xseq/.
 */

import org.w3c.dom.Document;
import org.w3c.dom.Element;

import org.w3c.dom.NodeList;

public class Main {
    /**
     * Add XML IDs to a Document. This method is one of the hearts of the xseq
     * system. It runs through a DOM Document tree, and for each element found
     * adds (updates) an ID attribute called "id".
     * 
     * <P>
     * For now the value is a simple sequence.
     * 
     * @param doc
     *            The DOM Document to which IDs are added
     */
    public static void addIDs(Document doc) {
        // * means all elements
        NodeList nodelist = doc.getElementsByTagName("*");

        // does this need to be thread protected?

        for (int i = 0; i < nodelist.getLength(); i++) {
            Element element = (Element) nodelist.item(i);

            element.setAttribute("id", "n" + i);
        }
    }
}