List of usage examples for org.w3c.dom Element getAttribute
public String getAttribute(String name);
From source file:Main.java
public static String getAttribute(Element elem, String attr, String def) { NodeList nlist = elem.getElementsByTagName("attribute"); String value = null;//from w ww .ja v a 2s .c o m for (int i = 0; i < nlist.getLength(); i++) { Element node = (Element) nlist.item(i); if (attr.equals(node.getAttribute("name"))) { value = node.getTextContent(); break; } } if (value == null) { value = def; } return value; }
From source file:Main.java
public static String getAttribute(Element e, String attrName, String def) { String result = e.getAttribute(attrName); if (!hasValue(result)) result = def;// w ww . j av a 2 s .c o m return result; }
From source file:Main.java
public static HashMap<String, Element> createIndex(Element root, String tagName, String idName) { NodeList nodes = root.getElementsByTagName(tagName); HashMap<String, Element> index = new HashMap<>(nodes.getLength()); for (int i = 0; i < nodes.getLength(); i++) { Element el = (Element) nodes.item(i); String key = el.getAttribute(idName); if (!key.isEmpty()) index.put(key, el);/*from w ww .j a v a 2s. co m*/ } return index; }
From source file:Main.java
public static Element getElement(Element parentElement, String nodeName, String id) { NodeList nodeList = parentElement.getElementsByTagName(nodeName); int i;//w ww . j a v a2s .com for (i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; if (id.equals(element.getAttribute(idName))) { return element; } } } return null; }
From source file:Main.java
/** */// w ww. j a v a 2 s . com public static Element getElementWithAttribute(String tagName, String attribute, String attributeValue, Element searchIn) { ArrayList<Element> list = getElementsByTag(tagName, searchIn); for (Element e : list) { if (attributeValue.equals(e.getAttribute(attribute))) { return e; } } return null; }
From source file:Main.java
public static boolean isDitaType(Element element, String ditaMapType) { String classValue = element.getAttribute(DITA_CLASS_ATTNAME); if (classValue != null) { // NOTE: because class values always start with "+" or "-", // index can never be 0. return (classValue.indexOf(" " + ditaMapType.trim() + " ") > 0 || classValue.endsWith(" " + ditaMapType.trim())); }//from w ww .j a v a2 s . com return false; }
From source file:Main.java
private static List<String> getMappers(List<Element> mappersList) { List<String> mappers = new ArrayList<String>(); for (int i = 0; i < mappersList.size(); i++) { Element mapperElement = mappersList.get(i); String mapper = mapperElement.getAttribute(ATTRIBUTE_TARGET); mappers.add(mapper);/*from w ww . jav a 2 s .c om*/ } return mappers; }
From source file:Main.java
public static String selectStringAttribute(Element parent, String attrName, String defaultVal) { String result = parent.getAttribute(attrName); if (result == null || result.isEmpty()) { // Logger.getLogger(XmlUtil.class.getName()).log(Level.INFO, // "Attribute {0} is not found", attrName); return defaultVal; }//from ww w .ja v a2 s . c om return result; }
From source file:Main.java
public static String getNamedChildValue(Element element, String name) { Element e = getNamedChild(element, name); return e == null ? null : e.getAttribute("value"); }
From source file:Main.java
public static String getAttribute(Element element, String attributeName) { return (element.hasAttribute(attributeName) ? element.getAttribute(attributeName) : null); }