Java XML Element Value getElementValue(Element element, String elementName)

Here you can find the source of getElementValue(Element element, String elementName)

Description

This method return role name from xml file.

License

BSD License

Parameter

Parameter Description
element String- privilege Element
elementName -Element name for which value has to be return

Return

String Role name

Declaration

public static String getElementValue(Element element, String elementName) 

Method Source Code

//package com.java2s;
/*L//  w ww.  j  a  v  a2  s  .  c om
 * Copyright Washington University in St. Louis, SemanticBits, Persistent Systems, Krishagni.
 *
 * Distributed under the OSI-approved BSD 3-Clause License.
 * See http://ncip.github.com/commons-module/LICENSE.txt for details.
 */

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

public class Main {
    /**
     * This method return role name from xml file.
     * @param element String- privilege Element
     * @param elementName -Element name for which value has to be return
     * @return String Role name
     */
    public static String getElementValue(Element element, String elementName) {
        String roleName = "";
        NodeList elementList = element.getElementsByTagName(elementName);
        Element ele = (Element) elementList.item(0);
        NodeList valueNodeList = ele.getChildNodes();
        Node node = ((Node) valueNodeList.item(0));
        if (node != null) {
            roleName = node.getNodeValue();
        }
        return roleName;
    }
}

Related

  1. getElementValue(Element element)
  2. getElementValue(Element element)
  3. getElementValue(Element element)
  4. getElementValue(Element element)
  5. getElementValue(Element element)
  6. getElementValue(Element element, String name)
  7. getElementValue(Element element, String tag)
  8. getElementValue(Element element, String tagName)
  9. getElementValue(Element elm)