Java XML Node Name getNodeContent(Node n, String nodename)

Here you can find the source of getNodeContent(Node n, String nodename)

Description

get Node Content

License

Open Source License

Declaration

public static String getNodeContent(Node n, String nodename) 

Method Source Code

//package com.java2s;
/*******************************************************************************
*
*  JOpac2 (C) 2002-2007 JOpac2 project//from w w w. j a v a2  s  .co m
*
*     This file is part of JOpac2. http://jopac2.sourceforge.net
*
*  JOpac2 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.
*
*  JOpac2 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 JOpac2; if not, write to the Free Software
*  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*
*******************************************************************************/

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Main {
    public static String getNodeContent(Node n, String nodename) {
        Node r = getNode(n, nodename);
        if (r != null)
            return r.getTextContent();
        else
            return null;
    }

    public static Node getNode(Node node, String nodename) {
        Node r = null;
        if (node.getNodeName().equals(nodename)) {
            r = node;
        } else {
            NodeList children = node.getChildNodes();
            int len = children.getLength();
            for (int i = 0; i < len && r == null; i++)
                r = getNode(children.item(i), nodename);
        }
        return r;
    }
}

Related

  1. getNode(Node iNode, String iNodeName)
  2. getNode(Node iNode, String iNodeName)
  3. getNode(Node node, String nodeName)
  4. getNode(Node node, String nodeName)
  5. getNodeContent(Node item, String nodeName)
  6. getNodeName(Node node)
  7. getNodeName(Node node)
  8. getNodeName(Node node)
  9. getNodeName(Node node)