Java XML Element Get Value getTextContent(Element e, String name)

Here you can find the source of getTextContent(Element e, String name)

Description

get Text Content

License

Open Source License

Declaration

static public String getTextContent(Element e, String name) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2006 Vladimir Silva and others.
 * 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://from   w w  w  . j  a v a  2 s .com
 *     Vladimir Silva - initial API and implementation
 *******************************************************************************/

import org.w3c.dom.Element;

import org.w3c.dom.NodeList;

public class Main {
    static public String getTextContent(Element e, String name) {
        NodeList nl = e.getElementsByTagName(name);

        try {
            return (nl != null && nl.getLength() > 0) ? nl.item(0).getTextContent().trim() : null;

        } catch (NullPointerException ex) {
            return null;
        }
    }
}

Related

  1. getText(final Element el)
  2. getText(final Element element)
  3. getText(final Element element, final StringBuilder sbuf, final boolean decend)
  4. getText(final Element tag)
  5. getTextContent(Element e)
  6. getTextContent(Element el)
  7. getTextContent(Element ele)
  8. getTextContent(Element element)
  9. getTextContent(Element element)