List of usage examples for org.w3c.dom NamedNodeMap getNamedItem
public Node getNamedItem(String name);
From source file:Main.java
public static List<Node> getNodesWithKey(Node parent, String key, Set<String> values, boolean all_of_them) { ArrayList<Node> valid = new ArrayList<>(); NodeList children = parent.getChildNodes(); Node current;/*from w w w .jav a2s .co m*/ for (int i = 0; i < children.getLength(); i++) { current = children.item(i); NamedNodeMap attrs = current.getAttributes(); if (attrs != null) { Node keynode = attrs.getNamedItem(key); if (keynode != null) if (values == null || values.contains(keynode.getNodeValue())) { valid.add(current); if (!all_of_them) break; } } } return valid; }
From source file:Main.java
public static String getAttributeValue(File xmlfile, String nodeXpath, String attributeName) throws ParserConfigurationException, SAXException, IOException, XPathExpressionException { //logger.debug("Getting the attribute value from the xml file" + xmlfile.toString()); // get the Document object. Document doc = getDocument(xmlfile); // get the Node Object for the xpath. Node node = getNodeObject(nodeXpath, doc); NamedNodeMap attr = node.getAttributes(); // Get the Attribute Value returned as a String String attributeValue = attr.getNamedItem(attributeName).getNodeValue(); //logger.debug("Attribute name " + attributeName + " and the value is " + attributeValue); //logger.debug("Returning attribute value as " + attributeValue); return attributeValue; }
From source file:Main.java
public static Node getNamedItem(final NamedNodeMap nodeMap, final String name) { return nodeMap == null ? null : nodeMap.getNamedItem(name); }
From source file:Main.java
/** * Returns the given attribute of a node, if it exists * Otherwise, returns null/* w ww .java2 s .co m*/ */ static Node get_named_attribute(Node node, String att_name) { if (node == null) return null; // Does the node have attributes? NamedNodeMap attributes = node.getAttributes(); if (attributes != null) { // Does the node have this attribute? return attributes.getNamedItem(att_name); } // No attributes return null; }
From source file:Main.java
/** * Set node's attribute.//from w w w . j a v a 2s . c o m * * @param node * the node * @param attributeName * the attribute name * @param value * the value */ public static void setNodeAttributeValue(Node node, String attributeName, String value) { if (null == node) { // Do Nothing return; } NamedNodeMap attributes = node.getAttributes(); if (null == attributes) { // Do Nothing return; } Node n = attributes.getNamedItem(attributeName); if (null == n) { // Do Nothing return; } n.setNodeValue(value); }
From source file:Main.java
public static String getAttributeValue(Node node, String attributeName) { if (node == null || attributeName == null) { return null; }/* w w w.j a va 2 s . c o m*/ NamedNodeMap attributes = node.getAttributes(); if (attributes == null) { return null; } Node attribute = attributes.getNamedItem(attributeName); if (attribute != null) { return attribute.getNodeValue(); } return null; }
From source file:Main.java
/** * Gets an attribute value by name, returning null if not found *//*from ww w. j av a 2 s. com*/ public static String getAttributeByName(Node content, String attributeName) { if (content != null) { NamedNodeMap atts = content.getAttributes(); if (atts == null) { return null; } Node att = atts.getNamedItem(attributeName); if (att != null) { return att.getNodeValue(); } } return null; }
From source file:Main.java
public static String getAttribute(final Node node, final String attributeName) { final NamedNodeMap tmpMap = node.getAttributes(); if (tmpMap == null) { return null; }//w w w . j a v a2s . c o m final Node tmpNode = tmpMap.getNamedItem(attributeName); if (tmpNode == null) { return null; } return tmpNode.getNodeValue(); }
From source file:Main.java
/** * Retrieves the desired attribute from the given Node * /*from w w w . j a v a2 s .c o m*/ * @param xml the Node * @param attr the attribute name String * @return the attribute value String **/ public final static String getAttribute(final Node xml, final String attr) { if (xml == null) { return null; } final NamedNodeMap attrs = xml.getAttributes(); return attrs == null ? null : xmlFindTextNode(attrs.getNamedItem(attr)); }
From source file:Main.java
public static String getAttr(Node node, String name) throws DOMException { assert node != null; try {//www. j a va 2s . c o m NamedNodeMap attributes = node.getAttributes(); if (attributes == null) throw new Exception(""); Node attr = attributes.getNamedItem(name); if (attr == null) throw new Exception(""); String value = attr.getNodeValue(); if (value == null) throw new Exception(""); return value; } catch (Exception e) { throw new DOMException(DOMException.NOT_FOUND_ERR, String.format("attribute %s is missing at node %s", name, node.getNodeName())); } }