Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
// This file is part of nzdis-util package. See the file LICENSE for copyright information

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

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

public class Main {
    /**
     * Creates ElementNode for given tag with particular text as content.
     */
    public static Element createTextNode(String tag, String content) throws ParserConfigurationException {
        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
        Document doc = docBuilder.newDocument();
        Element node = doc.createElement(tag);
        Text t = doc.createTextNode(content);
        node.appendChild(t);

        return node;
    }
}