Java XML Element Get Value getTexts(Element root, String elementName)

Here you can find the source of getTexts(Element root, String elementName)

Description

get Texts

License

GNU General Public License

Declaration

public static String[] getTexts(Element root, String elementName) 

Method Source Code

//package com.java2s;
/* ***** BEGIN LICENSE BLOCK *****
 * Version: GPL 2.0// w ww.j a va  2s  .c  om
 *
 * The contents of this file are subject to the GNU General Public
 * License Version 2 or later (the "GPL").
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Initial Developer of the Original Code is
 *   MiniG.org project members
 *
 * ***** END LICENSE BLOCK ***** */

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

public class Main {
    public static String[] getTexts(Element root, String elementName) {
        NodeList list = root.getElementsByTagName(elementName);
        String[] ret = new String[list.getLength()];
        for (int i = 0; i < list.getLength(); i++) {
            Text txt = (Text) list.item(i).getFirstChild();
            if (txt != null) {
                ret[i] = txt.getData();
            } else {
                ret[i] = ""; //$NON-NLS-1$
            }
        }
        return ret;
    }
}

Related

  1. getTextElementValue(Element ele)
  2. getTextFromFirstSubEleByName(Element element, String tagName)
  3. getTextFromTag(Element current, String tag)
  4. getTextList(Element elem, String name)
  5. getTextOfElement(Element e)
  6. getTextString(Element e)
  7. getTextTrim(Element element)
  8. getTextTrim(Element element)
  9. getTextValue(Element el, String tagName)