List of usage examples for org.w3c.dom Node getAttributes
public NamedNodeMap getAttributes();
NamedNodeMap
containing the attributes of this node (if it is an Element
) or null
otherwise. From source file:Main.java
/** * @param node/*from w ww . ja v a 2 s . c o m*/ * @param attributeName * @return the String value of the given attributeName for the given node. null if the attributeName is not found or the input node is null. */ public static String nullSafeGetStringAttribute(Node node, String attributeName) { if (node != null) { Node namedItem = node.getAttributes().getNamedItem(attributeName); if (namedItem != null) { return namedItem.getNodeValue(); } } return null; }
From source file:Main.java
/** * Allows to retrieve the UUID of the node. * @param node node to be modified./* w w w. jav a 2 s .c o m*/ * @return the UUID of the node. */ public static String getNodeId(Node node) { String nodeId = null; NamedNodeMap nnm = node.getAttributes(); if (nnm != null) { Attr a = (Attr) nnm.getNamedItemNS(CEFX_NAMESPACE, CEFXUID); if (a == null) { String name = CEFXUID; a = (Attr) nnm.getNamedItem(name); } if (a != null) { nodeId = a.getNodeValue(); } } return nodeId; }
From source file:Main.java
public static String getAttribute(Node node, String attributeName, String defaultValue) { Node attribute = node.getAttributes().getNamedItem(attributeName); return attribute != null ? attribute.getTextContent().trim() : defaultValue; }
From source file:Main.java
/** * Utility method to fetch the attribute value from the given * element node//from ww w. j a va 2 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
public static String getAttribute(Node node, String name) { if (node == null) { return null; }// w w w.j ava 2 s. co m Node val = node.getAttributes().getNamedItem(name); if (val == null) { return null; } return val.getNodeValue(); }
From source file:Main.java
public static Map<String, String> getMapOfAttributes(Node elem) { Map<String, String> attrs = new HashMap<String, String>(); NamedNodeMap m = elem.getAttributes(); if (m != null) { for (int i = 0; i < m.getLength(); ++i) { Attr a = (Attr) m.item(i); attrs.put(a.getName(), a.getValue()); }/*from w w w . j a va 2s. c om*/ } return attrs; }
From source file:Main.java
public static float readFloat(Node node, String attributeName, float def) { try {//from w ww .java 2s .com return Float.parseFloat(node.getAttributes().getNamedItem(attributeName).getNodeValue()); } catch (Exception ex) { return def; } }
From source file:Main.java
public static String getAttributeValue(String attributeName, Node xmlNode) { if (xmlNode == null) return null; if (xmlNode.getAttributes() == null) return null; if (xmlNode.getAttributes().getLength() == 0) return null; Node n = xmlNode.getAttributes().getNamedItem(attributeName); if (n == null) return null; return n.getTextContent(); }
From source file:Main.java
/** * Sets an attribute on the specified node, with the given name and value *///w w w . j a v a 2s . co m public static void setStrValue(Node node, String name, String value) { Attr att = node.getOwnerDocument().createAttribute(name); node.getAttributes().setNamedItem(att); att.setValue(value); }
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; }