Here you can find the source of addTextElement(Document document, Node parentNode, String elementName, String elementText)
Parameter | Description |
---|---|
document | the document where the parent resides, and where the new text element will reside. The document may or may not be the parent node itself. |
parentNode | the parent node of the new text element. |
key | the name of the element. |
value | the string within the element. |
public static void addTextElement(Document document, Node parentNode, String elementName, String elementText)
//package com.java2s; /******************************************************************************* * Copyright 2013-2014 Esri/*from ww w .j a v a 2 s. c o m*/ * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. ******************************************************************************/ import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; public class Main { /** * Convenience method for adding an XML text element. For example, if you call * the method like this:<br/> * <br/> * <code>Utilities.addTextElement(parent, "lastName", "Lockwood");</code><br/> * <br/> * The new node, when rendered as a string, will look like this:<br/> * <br/> * <code><lastName>Lockwood</lastName> * @param document the document where the parent resides, and where the new text * element will reside. The document may or may not be the parent * node itself. * @param parentNode the parent node of the new text element. * @param key the name of the element. * @param value the string within the element. */ public static void addTextElement(Document document, Node parentNode, String elementName, String elementText) { Element textElement = document.createElement(elementName); textElement.appendChild(document.createTextNode(elementText)); parentNode.appendChild(textElement); } }