Here you can find the source of getString(final Element element)
Parameter | Description |
---|---|
element | Element |
public static String getString(final Element element)
//package com.java2s; /******************************************************************************* * Copyright (c) 2015-2016 Oak Ridge National Laboratory. * 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 *******************************************************************************/ import org.w3c.dom.Element; import org.w3c.dom.Node; public class Main { /** Get string value of an element. * @param element Element/* ww w. j a va2s . c o m*/ * @return String of the node. Empty string if nothing found. */ public static String getString(final Element element) { final Node text = element.getFirstChild(); if (text == null) // <empty /> node return ""; if ((text.getNodeType() == Node.TEXT_NODE || text.getNodeType() == Node.CDATA_SECTION_NODE)) return text.getNodeValue(); return ""; } }