All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.andromedaioc.util.XmlUtils Maven / Gradle / Ivy

The newest version!
package net.sf.andromedaioc.util;

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

public class XmlUtils {

    private XmlUtils() {
    }

    public static Node extractAttributeNode(Node node, String attributeName) {
        NamedNodeMap attributes = node.getAttributes();
        return attributes.getNamedItem(attributeName);
    }

    public static String extractStringAttributeValue(Node node, String attributeName) {
        Node attribute = extractAttributeNode(node, attributeName);
        return attribute == null ? null : attribute.getNodeValue();
    }

    public static Class extractClassAttributeValue(Node node, String attributeName) throws ClassNotFoundException {
        String className = extractStringAttributeValue(node, attributeName);
        return className == null ? null : Class.forName(className); // ClassLoader.getSystemClassLoader().loadClass(className);
    }

    public static boolean extractBooleanAttributeValue(Node node, String attributeName, boolean defaultValue) {
        String value = extractStringAttributeValue(node, attributeName);
        return value == null ? defaultValue : Boolean.valueOf(value);
    }

    public static Integer extractIntegerAttributeValue(Node node, String attributeName) {
        String value = extractStringAttributeValue(node, attributeName);
        return value == null ? null : Integer.parseInt(value);
    }

    public static Node findChildElementNode(Node parentNode, String childNodeName) {
        NodeList childNodes = parentNode.getChildNodes();
        for(int i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy