List of usage examples for org.w3c.dom NamedNodeMap getNamedItem
public Node getNamedItem(String name);
From source file:Main.java
/** * Removes a named attribute of a Node<p> * @param node The node to search/*w ww .ja v a2 s .c o m*/ * @param attr The name of the attribute to remove */ public synchronized static void removeAttribute(Node node, String attr) { if (node == null) throw new IllegalArgumentException("Node argument cannot be null"); if (attr == null) throw new IllegalArgumentException("Node attribute argument cannot be null"); NamedNodeMap map = node.getAttributes(); if (map != null) { Node an = map.getNamedItem(attr); if (an != null) map.removeNamedItem(attr); } }
From source file:Main.java
public static String getAttribute(Node node, String attrName) { NamedNodeMap attr = node.getAttributes(); if (attr != null) { Node nodeAttr = attr.getNamedItem(attrName); if (nodeAttr != null) { return nodeAttr.getNodeValue(); }/* w w w.jav a 2s . co m*/ } return null; }
From source file:Main.java
/** * Gets a named attribute of a Node<p> * @param node The node to search/*from ww w .j av a2 s . c om*/ * @param attr The name of the attribute to get */ public synchronized static String getAttribute(Node node, String attr) { if (node == null) throw new IllegalArgumentException("Node argument cannot be null"); if (attr == null) throw new IllegalArgumentException("Node attribute argument cannot be null"); NamedNodeMap map = node.getAttributes(); if (map != null) { Node an = map.getNamedItem(attr); if (an != null) return an.getNodeValue(); } return null; }
From source file:Main.java
static String getAttributeValue(final Node node, final String attributeName) { if (node == null || attributeName == null) { return null; }//from w ww .j av a 2 s . com final NamedNodeMap attrMap = node.getAttributes(); final Node attrNode = attrMap.getNamedItem(attributeName); if (attrNode != null) { return attrNode.getNodeValue(); } return null; }
From source file:Main.java
/** * Gets the node value as time./* w w w .j av a 2 s .c o m*/ * *@param node Description of the Parameter *@return The nodeValueAsTime value *@exception DOMException Description of the Exception */ public final static long getNodeValueAsTime(Node node) throws DOMException { if (node == null) return -1; NamedNodeMap attrs = node.getAttributes(); Node attr = attrs.getNamedItem("Unit"); int factor = 1; String unit = attr.getNodeValue(); if (unit.equals("sec")) { factor = 1000; } else if (unit.equals("min")) { factor = 60000; } else if (unit.equals("hr")) { factor = 3600000; } else if (unit.equals("day")) { factor = 86400000; } node = node.getFirstChild(); if (node != null) { String time = node.getNodeValue().trim(); return Integer.parseInt(time) * factor; } return -1; }
From source file:Main.java
/** * Returns the attribute value with the given id for the Node * //ww w . j a va 2 s. c om * @param n * @param id * @return */ public static String getAttribute(Node n, String id) { String result = null; NamedNodeMap attrMap = n.getAttributes(); if (null != attrMap) { Node attr = attrMap.getNamedItem(id); result = (attr == null) ? null : attr.getNodeValue(); } if (null != result) { result = result.trim(); } return result; }
From source file:Main.java
public static String getAttributeValue(Node node, String attributeName) { NamedNodeMap attributes = node.getAttributes(); if (null != attributes) { Node namedItem = attributes.getNamedItem(attributeName); if (null != namedItem) { return namedItem.getNodeValue(); }//from w w w. j av a 2s . c o m } return ""; }
From source file:Main.java
/** * Extracts an attribute from a node.//from ww w . j a v a2s.c o m * * @param node * @param attr * @param def * @return The value of the attribute, or def */ public static String getAttribute(Node node, String attr, String def) { NamedNodeMap attrs = node.getAttributes(); Node val = attrs.getNamedItem(attr); if (val != null) { return val.getNodeValue(); } return def; }
From source file:XMLUtils.java
/** * Returns the value of the attribute of the given element. * @param base the element from where to search. * @param name of the attribute to get.// w ww.java 2s . c o m * @return the value of this element. */ public static String getAttributeValue(final Element base, final String name) { // get attribute of this element... NamedNodeMap mapAttributes = base.getAttributes(); Node node = mapAttributes.getNamedItem(name); if (node != null) { return node.getNodeValue(); } return null; }
From source file:Main.java
/** * Returns whether the given XML DOM node contains all of the given attributes. * @param node the XML node to examine/*from www . j a va 2 s. c o m*/ * @param names a variable-length list of attribute names to check * @return true if all attributes exist, false if not */ public static boolean hasAttributes(Node node, String... names) { NamedNodeMap attrs = node.getAttributes(); for (String name : names) { if (attrs.getNamedItem(name) == null) { return false; } } return true; }