Example usage for org.w3c.dom Element getAttribute

List of usage examples for org.w3c.dom Element getAttribute

Introduction

In this page you can find the example usage for org.w3c.dom Element getAttribute.

Prototype

public String getAttribute(String name);

Source Link

Document

Retrieves an attribute value by name.

Usage

From source file:org.drools.container.spring.namespace.XsdParser.java

@SuppressWarnings("unchecked")
public static void parse(Element element, ParserContext parserContext, BeanDefinitionBuilder factory) {

    List<Element> childElements = DomUtils.getChildElementsByTagName(element, "jaxb-conf");
    if (!childElements.isEmpty()) {
        Element conf = childElements.get(0);

        String systemId = conf.getAttribute(SYSTEM_ID);
        systemId = (systemId != null && systemId.trim().length() > 0) ? systemId : "xsd";

        String schemaLanguage = conf.getAttribute(SCHEMA_LANGUAGE);
        schemaLanguage = (schemaLanguage != null && schemaLanguage.trim().length() > 0) ? schemaLanguage
                : "XMLSCHEMA";

        Options options = new Options();
        options.setSchemaLanguage(Language.valueOf(schemaLanguage));

        JaxbConfiguration jaxbConf = KnowledgeBuilderFactory.newJaxbConfiguration(new Options(), systemId);

        factory.addPropertyValue("resourceConfiguration", jaxbConf);
    } else {/*  ww w .  ja  v  a  2s.  c o m*/
        JaxbConfiguration jaxbConf = KnowledgeBuilderFactory.newJaxbConfiguration(new Options(), "xsd");

        factory.addPropertyValue("resourceConfiguration", jaxbConf);
    }
}

From source file:Main.java

public static String getTagPropertyValue(Element root, String tagName, String attr) {
    Element interestedNodes = getChildElement(root, tagName);

    String desc = interestedNodes.getAttribute(attr);

    return desc;//from ww w  .j  a va2 s . c om
}

From source file:Main.java

public static QName getAttributeNSName(Element e, String attrName) {
    String attrValue = e.getAttribute(attrName);
    return getNSName(e, attrValue);
}

From source file:Main.java

public static Element findElementByAttribute(Node node, String tagName, String attrName, String attrValue) {
    Element result = null;/*w ww.j  a  va  2 s  . c o m*/
    NodeList nodeList = node.getChildNodes();
    if (nodeList == null) {
        return result;
    }
    for (int i = 0; i < nodeList.getLength(); ++i) {
        Element element = checkIfElement(nodeList.item(i), tagName);
        if (element != null && element.getAttribute(attrName).equals(attrValue)) {
            result = element;
            break;
        }
    }
    return result;
}

From source file:Main.java

/**
 * Finds and returns the first child node with the given name and
 * attribute name, value pair.// ww  w  .  j a  v a 2 s.c o  m
 */
public static Element getFirstChildElement(Node parent, String elemName, String attrName, String attrValue) {

    // search for node
    Node child = parent.getFirstChild();
    while (child != null) {
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            Element element = (Element) child;
            if (element.getNodeName().equals(elemName) && element.getAttribute(attrName).equals(attrValue)) {
                return element;
            }
        }
        child = child.getNextSibling();
    }

    // not found
    return null;

}

From source file:Main.java

public static String attributeStringValue(Element e, String attr, String defaultValue) {
    if (!e.hasAttribute(attr)) {
        return defaultValue;
    }//from   w  ww. j  av  a 2s.  c  o  m
    return e.getAttribute(attr);
}

From source file:Main.java

public static String getAttributeFromElement(Element element, String attributeName) {
    String result = null;/*from  www  .  j  ava 2 s. c  o m*/
    if (element != null) {
        result = element.getAttribute(attributeName).toString();
    }
    if (result != null && result.length() == 0) {
        result = null;
    }
    return result;
}

From source file:Main.java

/**
 * Finds and returns the last child node with the given name and
 * attribute name, value pair.//from  w w  w  .  jav  a 2  s.  c  o m
 */
public static Element getLastChildElement(Node parent, String elemName, String attrName, String attrValue) {

    // search for node
    Node child = parent.getLastChild();
    while (child != null) {
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            Element element = (Element) child;
            if (element.getNodeName().equals(elemName) && element.getAttribute(attrName).equals(attrValue)) {
                return element;
            }
        }
        child = child.getPreviousSibling();
    }

    // not found
    return null;

}

From source file:Main.java

public static URI getURIAttribute(Element el, String attr, URI defaultValue) {
    if (el.hasAttribute(attr)) {
        try {//from w w w.  j av a2  s.c  om
            return new URI(el.getAttribute(attr));
        } catch (URISyntaxException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    return defaultValue;
}

From source file:Main.java

public static String readAttributeValue(Element e, String attributeName, String defaultValue) {
    if (e.hasAttribute(attributeName)) {
        return e.getAttribute(attributeName);
    } else {//from   w w  w . j  av a  2s.com
        return defaultValue;
    }
}