get Integer Property XML Parent Element - Java XML

Java examples for XML:XML Element Value

Description

get Integer Property XML Parent Element

Demo Code


//package com.java2s;

import org.w3c.dom.Element;

import org.w3c.dom.NodeList;

public class Main {
    public static final String PROPERTY_NODE = "property";
    public static final String NAME_ATTR = "name";
    public static final String INTEGER_ATTR = "intvalue";

    public static int getIntegerProperty(Element properties, String name) {
        return new Integer(getPropertyNode(properties, name)
                .getAttributes().getNamedItem(INTEGER_ATTR).getNodeValue());
    }/*from   ww w  . java2  s.c o  m*/

    public static Element getPropertyNode(Element properties, String name) {
        NodeList nodeList = properties.getElementsByTagName(PROPERTY_NODE);
        for (int i = 0; i < nodeList.getLength(); i++) {
            Element element = (Element) nodeList.item(i);
            if (name.equals(element.getAttributes().getNamedItem(NAME_ATTR)
                    .getNodeValue())) {
                return element;
            }
        }
        return null;
    }
}

Related Tutorials