Java XML Element Text getContentText(Element elementNode)

Here you can find the source of getContentText(Element elementNode)

Description

get Content Text

License

Open Source License

Declaration

public static String getContentText(Element elementNode) 

Method Source Code


//package com.java2s;
/*//  w  w w  .  ja  v a  2s. co  m
Laszlo, a reception software for a satellite-based push service.
Copyright (C) 2004-2006  Roland Fulde
    
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
    
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
    
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
    
Project home page: http://laszlo.berlios.de/
*/

import org.w3c.dom.*;

public class Main {
    public static String getContentText(Element elementNode) {
        StringBuffer result = new StringBuffer();
        NodeList children = elementNode.getChildNodes();
        for (int c = 0; c < children.getLength(); c++) {
            Node child = children.item(c);
            if ((child.getNodeType() == Node.TEXT_NODE) && (child instanceof Text)) {
                String name = ((Text) child).getData();
                result.append(name);
            }
        }
        return result.toString();
    }
}

Related

  1. getContent(Element element)
  2. getContent(Element element)
  3. getContent(Element element)
  4. getContentFromElement(Element element, String namespaceURI, String localName)
  5. getContentText(Element element)
  6. getElementText(Element elem)
  7. getElementText(Element elem)
  8. getElementText(Element elem, boolean mandatory)
  9. getElementText(Element elem, String name)