Here you can find the source of getCascadeValue(final Element elem, final String attrName)
Parameter | Description |
---|---|
elem | attribute parent element |
attrName | attribute name |
public static String getCascadeValue(final Element elem, final String attrName)
//package com.java2s; //License from project: Apache License import org.w3c.dom.*; public class Main { /**/* w w w . ja v a 2s. c o m*/ * Get cascaded attribute value. * * @param elem attribute parent element * @param attrName attribute name * @return attribute value, {@code null} if not set */ public static String getCascadeValue(final Element elem, final String attrName) { Element current = elem; while (current != null) { final Attr attr = current.getAttributeNode(attrName); if (attr != null) { return attr.getValue(); } final Node parent = current.getParentNode(); if (parent != null && parent.getNodeType() == Node.ELEMENT_NODE) { current = (Element) parent; } else { break; } } return null; } /** * Get attribute value. * * @param elem attribute parent element * @param attrName attribute name * @return attribute value, {@code null} if not set */ public static String getValue(final Element elem, final String attrName) { final Attr attr = elem.getAttributeNode(attrName); if (attr != null && !attr.getValue().isEmpty()) { return attr.getValue(); } return null; } }