Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2004-2010 IBM Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

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

import org.w3c.dom.Text;

public class Main {
    /**
     * creates two elements: - one for the tag - one for the value and appends the
     * value as the child of the tag element returns a reference to the tag
     * element. Both elements are created in the document.
     */
    public static Element createTaggedElement(Document doc, String tag, String value) {
        Element tagElement = doc.createElement(tag);
        Text valueElement = doc.createTextNode(value);
        tagElement.appendChild(valueElement);
        return tagElement;
    }

    public static Element createTaggedElement(Document doc, String tag, int value) {
        return createTaggedElement(doc, tag, String.valueOf(value));
    }
}