Create XML Element and wrap text Content - Java XML

Java examples for XML:DOM Element Create

Description

Create XML Element and wrap text Content

Demo Code


//package com.java2s;

import org.w3c.dom.Element;

public class Main {
    static public void textContentTag(Element parent, String tagName,
            String content) {//from  ww  w.  j av a2 s  .  c o  m
        Element tag = parent.getOwnerDocument().createElement(tagName);
        tag.setTextContent(content);
        parent.appendChild(tag);
    }

    static public Element createElement(Element parent, String tagName) {
        Element tag = parent.getOwnerDocument().createElement(tagName);
        parent.appendChild(tag);
        return tag;
    }
}

Related Tutorials