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
/** * Gets the attribute of the node./* w w w . j a v a 2s . com*/ * *@param node the node from which to get the attribute node *@param name the attribute name for which to get the node *@return The attribute node *@exception DOMException if an error occurs while getting the attribute * node */ public final static Node getAttribute(Node node, String name) throws DOMException { if (node != null && node.hasAttributes()) { NamedNodeMap attrs = node.getAttributes(); return attrs.getNamedItem(name); } return null; }
From source file:Main.java
public static Map<String, String> getAttrList(Node node) { Map<String, String> map = new HashMap<String, String>(); NamedNodeMap list = node.getAttributes(); if (list != null) for (int i = 0; i < list.getLength(); i++) { Attr attr = (Attr) list.item(i); map.put(attr.getName(), attr.getValue()); }// w w w . j a v a2 s .com return map; }
From source file:Main.java
/** * Returns formatted attributes of the node. * /* w w w .ja va2s. c o m*/ * @param node The node. * @return Formatted attributes. */ public static String formatAttributes(Node node) { StringBuilder sb = new StringBuilder(); NamedNodeMap attrs = node.getAttributes(); for (int i = 0; i < attrs.getLength(); i++) { Node attr = attrs.item(i); sb.append(' ').append(attr.getNodeName()).append("= '").append(attr.getNodeValue()).append("'"); } return sb.toString(); }
From source file:Main.java
public static String getNodeAttributeValue(String attrName, Node node) { if (node == null || attrName == null) { return null; }/*from www .j ava 2s. c om*/ NamedNodeMap attrs = node.getAttributes(); if (attrs == null) { return null; } Node attrNode = attrs.getNamedItem(attrName); if (attrNode != null) { return attrNode.getNodeValue(); } else { return null; } }
From source file:Main.java
public static void removeAllAttributes(Node node, String attrName) { // check if this node contains the attribute and remove it NamedNodeMap attrs = node.getAttributes(); if (attrs != null && attrs.getNamedItem(attrName) != null) { attrs.removeNamedItem(attrName); }/*from ww w. j a v a 2 s. c o m*/ // process recursively all children NodeList list = node.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { // Get child node Node childNode = list.item(i); // Visit child node removeAllAttributes(childNode, attrName); } }
From source file:Main.java
public static String getAttributeFromNode(Node node, String attributeName) { if (node == null || attributeName == null) return null; NamedNodeMap attributes = node.getAttributes(); Node attribute = attributes.getNamedItem(attributeName); String value = null;//from w w w . j av a 2s. c o m if (attribute != null) value = attribute.getNodeValue(); return value; }
From source file:Main.java
/** * Gets a attribute value./*from www . j a v a 2s . com*/ * * @param pNode * the p node * @param pAttributeName * the p attribute name * @return the attribute value */ public static String getAttributeValue(Node pNode, String pAttributeName) { String returnString = null; NamedNodeMap attributes = pNode.getAttributes(); if (attributes != null) { for (int i = 0; i < attributes.getLength(); i++) { if (attributes.item(i).getNodeName().equalsIgnoreCase(pAttributeName)) { returnString = attributes.item(i).getNodeValue(); break; } } } return returnString; }
From source file:lineage2.gameserver.utils.XMLUtil.java
/** * Method getAttributeIntValue.//from www . j ava 2 s .c o m * @param n Node * @param item String * @param dflt int * @return int */ public static int getAttributeIntValue(Node n, String item, int dflt) { final Node d = n.getAttributes().getNamedItem(item); if (d == null) { return dflt; } final String val = d.getNodeValue(); if (val == null) { return dflt; } return Integer.parseInt(val); }
From source file:Main.java
/** Return the value of an attribute of a node or an empty string if the attribute is not present./*from w w w. ja va2 s . c o m*/ */ static public String getAttribute(Node node, String att_name) { if (node == null) return ""; return getText(node.getAttributes().getNamedItem(att_name)); }
From source file:Main.java
/** * Gets an attribute value by name, returning null if not found *///w ww .j av a 2s.c o m 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; }