Java XML Element Text Set setElementSimpleValue(Element element, String simpleValue)

Here you can find the source of setElementSimpleValue(Element element, String simpleValue)

Description

In WTP, element values are text nodes that are child of the element.

License

Open Source License

Parameter

Parameter Description
element a parameter
simpleValue a parameter

Declaration

public static void setElementSimpleValue(Element element, String simpleValue) 

Method Source Code

//package com.java2s;
/******************************************************************************
 * Copyright (c) 2009-2013, Linagora//w  ww  . java2 s  . c om
 *
 * 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:
 *       Linagora - initial API and implementation
 *******************************************************************************/

import org.w3c.dom.Element;

import org.w3c.dom.NodeList;
import org.w3c.dom.Text;

public class Main {
    /**
     * In WTP, element values are text nodes that are child of the element.
     * <p>
     * And {@link Element#setTextContent(String)} is not implemented.
     * </p>
     *
     * @param element
     * @param simpleValue
     */
    public static void setElementSimpleValue(Element element, String simpleValue) {

        Text textNode = element.getOwnerDocument().createTextNode(simpleValue);
        NodeList children = element.getChildNodes();
        for (int i = 0; i < children.getLength(); i++)
            element.removeChild(children.item(i));

        element.appendChild(textNode);
    }
}

Related

  1. setElementAttr(Element element, String attr, String attrVal)
  2. setElementContent(final Node n, final String s)
  3. setElementsTextNodeValue(Node element, String value)
  4. setElementText(Element element, String text)
  5. setElementText(Element element, String value)
  6. setElementText(Element elm, String text)