List of usage examples for org.w3c.dom NamedNodeMap getNamedItem
public Node getNamedItem(String name);
From source file:Main.java
/** * Utility method to fetch the attribute value from the given * element node/*from w w w . jav a2 s . co m*/ * @param sNode * @param attribName * @return */ public static String getAttributeValue(Node sNode, String attribName) { String value = null; NamedNodeMap attrs = sNode.getAttributes(); if (attrs != null) { Node attr = attrs.getNamedItem(attribName); if (attr != null) { value = attr.getNodeValue(); } } return value; }
From source file:Main.java
/** * @param n Node to examine/*from w w w. ja va 2s. c om*/ * @param attr Attribute to look for * @return true if the Node contains the named Attribute */ public static boolean hasAttribute(Node n, String attr) { NamedNodeMap attrs = n.getAttributes(); if (attrs == null) return false; Node ret = attrs.getNamedItem(attr); if (ret == null) return false; else return true; }
From source file:Main.java
/** * Convenience method to retrieve an attribute of an element. * Note that calling element.getAttributes() once may be more efficient when pulling several attributes. * * @param element - element to retrieve the attribute from. * @param attr - attribute to get value. * @return attribute value or {@code null} *///w ww. j av a 2 s . c o m public static String determineAttributeValue(Node element, String attr) { NamedNodeMap attributes = element.getAttributes(); return attributes != null ? determineNodeValue(attributes.getNamedItem(attr)) : null; }
From source file:Main.java
public static ArrayList<HashMap<String, String>> getWhoList(Node currentNode, String tagName) { String result = ""; ArrayList<HashMap<String, String>> whoArrayList = new ArrayList<HashMap<String, String>>(); NodeList childNodeList = currentNode.getChildNodes(); for (int i = 0; i < childNodeList.getLength(); i++) { Node childNode = childNodeList.item(i); if (childNode.getNodeName().equals(tagName)) { HashMap<String, String> whoMap = new HashMap<String, String>(); NamedNodeMap attrNodeMap = childNode.getAttributes(); Node activity = attrNodeMap.getNamedItem("activity"); Node email = attrNodeMap.getNamedItem("email"); Node name = attrNodeMap.getNamedItem("name"); if (activity != null) { whoMap.put("activity", activity.getNodeValue()); }/*from w w w .ja v a 2 s . c om*/ if (email != null) { whoMap.put("email", email.getNodeValue()); } if (name != null) { whoMap.put("name", name.getNodeValue()); } whoArrayList.add(whoMap); } } return whoArrayList; }
From source file:Main.java
public static String getAttributeValue(Node node, String attrName) { if (node == null) return null; NamedNodeMap attrs = node.getAttributes(); if (attrs == null) return null; Node attrNode = attrs.getNamedItem(attrName); if (attrNode == null) return null; return attrNode.getNodeValue(); }
From source file:Main.java
public static Vector getElementsByAttribValue(org.w3c.dom.Element element, String attrib, String val) { NodeList desElements = element.getElementsByTagName("*"); Vector selElements = new Vector(desElements.getLength() / 10, 10); for (int i = 0; i < desElements.getLength(); i++) { org.w3c.dom.Node desElement = desElements.item(i); if (desElement.getNodeType() == org.w3c.dom.Element.ELEMENT_NODE) { NamedNodeMap attributeNodes = desElement.getAttributes(); org.w3c.dom.Node selAttribNode = attributeNodes.getNamedItem(attrib); if (selAttribNode != null && selAttribNode.getNodeValue().equalsIgnoreCase(val)) { selElements.add(desElement); }//from w w w . j a v a 2 s.c o m } } return selElements; }
From source file:Main.java
public static String getAttribute(Node pNode, String attrName) { try {// ww w . j ava 2 s. c om NamedNodeMap name = pNode.getAttributes(); if (name.getLength() > 0) { Node node = name.getNamedItem(attrName); if (node != null) { String attributeValue = name.getNamedItem(attrName).getNodeValue(); return attributeValue; } else { return null; } } else { return null; } } catch (Exception e) { return null; } }
From source file:Main.java
public static Vector getElementsByTagAndAttribValue(org.w3c.dom.Element element, String tag, String attrib, String val) { NodeList desElements = element.getElementsByTagName(tag); Vector selElements = new Vector(desElements.getLength() / 10, 10); for (int i = 0; i < desElements.getLength(); i++) { org.w3c.dom.Node desElement = desElements.item(i); if (desElement.getNodeType() == org.w3c.dom.Element.ELEMENT_NODE) { NamedNodeMap attributeNodes = desElement.getAttributes(); org.w3c.dom.Node selAttribNode = attributeNodes.getNamedItem(attrib); if (selAttribNode != null && selAttribNode.getNodeValue().equalsIgnoreCase(val)) { selElements.add(desElement); }/* w w w . j av a 2s .c o m*/ } } return selElements; }
From source file:Main.java
/** * @param node node/*from w w w. ja va2 s.c om*/ * @param name attribute name * @return the attribute with the given name or <code>null</code> * if none found */ public static Attr findAttribute(Node node, String name) { NamedNodeMap attrs = node.getAttributes(); if (attrs == null) { return null; } return (Attr) attrs.getNamedItem(name); }
From source file:Main.java
public static String readAttribute(Node element, String attributeName) { if (element == null) return null; NamedNodeMap attributes = element.getAttributes(); if (attributes == null) return null; Node value = attributes.getNamedItem(attributeName); if (value == null) return null; return value.getTextContent(); }