List of usage examples for org.w3c.dom Element getAttribute
public String getAttribute(String name);
From source file:Main.java
/** * Gets the attribute value./*from w ww . ja v a2 s .com*/ * * @param el * @param attributeName * * @return the attribute value */ public static String getAttributeValue(Element el, String attributeName) { return (null == el ? null : el.getAttribute(attributeName)); }
From source file:Main.java
public static String getAttributeValue(Element p_elem, String p_name) { return p_elem.getAttribute(p_name); }
From source file:Main.java
/** * Gets the attribute value.//w w w. j av a 2 s. c o m * @param pElement XML Element containing the attribute * @param pAttributeName Name of the attribute * @param pDefaultValue Default value (may be null) * @return The attribute's value, or the default value is not such attribute is defined */ static public String getAttribute(Element pElement, String pAttributeName, String pDefaultValue) { final String value = pElement.getAttribute(pAttributeName); return (value != null ? value : pDefaultValue); }
From source file:Main.java
public static Element findElement(Element parent, String elementNS, String elementName, String attrName, String attrValue) {// www. j a va 2s . com NodeList l = parent.getElementsByTagNameNS(elementNS, elementName); for (int i = 0; i < l.getLength(); i++) { Element e = (Element) l.item(i); String val = e.getAttribute(attrName); if (val != null && val.equals(attrValue)) { return e; } } return null; }
From source file:Main.java
/** * Returns attribute as boolean for class * * @param elem/* w ww . j ava2 s . c o m*/ * @param attribName * @return */ public static boolean getAttributeAsBoolean(Element elem, String attribName) { String atribVal = elem.getAttribute(attribName); boolean retVal = false; try { retVal = Boolean.valueOf(atribVal).booleanValue(); } catch (Exception e) { } return retVal; }
From source file:Main.java
/** * Extracts a list of integer values from the specified attribute. * @param element the element to fetch the integer list from * @param attributeName the name of the attribute containing the integer list * @return a list of integer values from the specified attribute *//*from w ww. j a v a 2 s. co m*/ public static List<Integer> getIntegerListAttribute(Element element, String attributeName) { String intListString = element.getAttribute(attributeName); if (intListString == null || intListString.length() == 0) { return Collections.emptyList(); } String[] intStrings = intListString.split(" "); //$NON-NLS-1$ List<Integer> intValues = new ArrayList<Integer>(intStrings.length); for (String intString : intStrings) { Integer intValue = Integer.valueOf(intString); intValues.add(intValue); } return intValues; }
From source file:Main.java
/** * Get name of specified generic element */// w w w .j a v a 2 s . co m public static String getGenericElementName(Element element) { if (element != null) return element.getAttribute(ATTR_NAME_NAME); return ""; }
From source file:Main.java
/** * Return all values associated with attributeName inside element specified by tag * @param document doc we work with// w w w . ja va 2s. c om * @param elementTag element containing desired attribute * @param attributeName name of attribute * @return List of values specified in XML array */ public static List<String> getListOfTagAttributeValues(Document document, String elementTag, String attributeName) { NodeList usesPermissionList = document.getElementsByTagName(elementTag); List<String> result = new ArrayList<String>(); for (int i = 0; i < usesPermissionList.getLength(); i++) { Node nNode = usesPermissionList.item(i); if (nNode.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNode; String value = eElement.getAttribute(attributeName); if (value != null && !value.isEmpty()) { result.add(value); } } } return result; }
From source file:Main.java
/** * Get first child element with the provided node name and attribute that * are direct child the provided element. * //from w ww . ja v a2 s.c o m * @param parent * @param name * @param attributeName * @param attributeValue * @return element if found, otherwise null */ public static Element getChildElementByNameAndAttribute(Element parent, String name, String attributeName, String attributeValue) { assertNotNull(parent); NodeList children = parent.getChildNodes(); Node node; for (int i = 0; i < children.getLength(); i++) { node = children.item(i); if (node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equals(name)) { Element element = (Element) node; if (element.getAttribute(attributeName).equals(attributeValue)) { return element; } } } return null; }
From source file:Main.java
public static String getAttribute(Element paramElement, String paramString) { return paramElement.getAttribute(paramString); }