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
static String attributeOrNull(Node node, String... attributes) { for (int i = 0; i < attributes.length; i++) { String attribute = attributes[i]; Node attr = node.getAttributes().getNamedItem(attribute); if (attr != null) return attr.getNodeValue(); }/*w ww . ja va 2s . c o m*/ return null; }
From source file:Main.java
/** * Gets the node value as date./* www . ja va2 s . co m*/ * *@param node Description of the Parameter *@return The nodeValueAsDate value *@exception DOMException Description of the Exception *@exception ParseException Description of the Exception */ public final static Date getNodeValueAsDate(Node node) throws DOMException, ParseException { if (node == null) return null; NamedNodeMap attrs = node.getAttributes(); Node attr = attrs.getNamedItem("DateTimeFormat"); // Date format String format = attr.getNodeValue().trim(); node = node.getFirstChild(); if (node != null) { String date = node.getNodeValue().trim(); DateFormat df = new SimpleDateFormat(format); return df.parse(date); } return null; }
From source file:com.l2jfree.gameserver.model.mapregion.L2MapRegionRestart.java
private static Location getLocation(Node node) { final int x = Integer.parseInt(node.getAttributes().getNamedItem("X").getNodeValue()); final int y = Integer.parseInt(node.getAttributes().getNamedItem("Y").getNodeValue()); final int z = Integer.parseInt(node.getAttributes().getNamedItem("Z").getNodeValue()); return new Location(x, y, z); }
From source file:Main.java
/** * Indicates if the passed node has the named atribute * @param node The node to inspect//w w w . jav a2s .c o m * @param name The name of the attribute to look for * @return true if the named attribute exists, false otherwise */ public static boolean hasAttribute(final Node node, final String name) { if (name == null || node == null) return false; final NamedNodeMap nnm = node.getAttributes(); for (int i = 0; i < nnm.getLength(); i++) { Attr attr = (Attr) nnm.item(i); if (attr.getName().equalsIgnoreCase(name)) { return true; } } return false; }
From source file:Main.java
private static String readXsdVersionFromFile(Document doc) { final String JBOSS_ESB = "jbossesb"; NodeList nodes = doc.getChildNodes(); if (nodes != null) { for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (JBOSS_ESB.equals(node.getNodeName())) { NamedNodeMap attributes = node.getAttributes(); for (int j = 0; j < attributes.getLength(); j++) { Node attribute = attributes.item(j); if ("xmlns".equals(attribute.getNodeName())) { String value = attribute.getNodeValue(); if (value.contains(JBOSS_ESB) && value.endsWith(".xsd")) return value.substring(value.lastIndexOf('/') + 1, value.length()); else throw new IllegalStateException( "The ESB descriptor points to an invalid XSD" + value); }/*w w w . ja v a 2 s.c om*/ } } } throw new IllegalArgumentException("No root node " + JBOSS_ESB + " found."); } else throw new IllegalArgumentException("Descriptor has no root element !"); }
From source file:Main.java
/** * Get the attribute value from specified node. * //from w ww.j a va 2s . c o m * @param node * the node * @param attributeName * the attribute name * @return the attribut value */ public static String getNodeAttribute(Node node, String attributeName) { if (null == node) { return null; } NamedNodeMap attributes = node.getAttributes(); if (null == attributes) { return null; } Node n = attributes.getNamedItem(attributeName); if (null == n) { return null; } return n.getNodeValue(); }
From source file:Main.java
/** * This grabs the attributes from a dom node and overwrites those values with those * specified by the overwrite map./* w w w .j a v a 2s .c o m*/ * * @param node node for building * @param overwrite map of attributes to overwrite * @return map of attributes */ public static Map<String, String> mapifyAttrs(Node node, Map<String, String> overwrite) { Map<String, String> map = new HashMap<String, String>(); NamedNodeMap nnMap = node.getAttributes(); for (int i = 0; i < nnMap.getLength(); i++) { Node attr = nnMap.item(i); map.put(attr.getNodeName(), attr.getNodeValue()); } if (overwrite != null) { for (Map.Entry<String, String> e : overwrite.entrySet()) { map.put(e.getKey(), e.getValue()); } } return map; }
From source file:Main.java
/** * Get all attributes as a Map from a node * * @param node the node taht contains the attributes to read * @return the values or a empty map/* www . j av a 2 s.c o m*/ */ public static HashMap<String, String> getAttributes(Node node) { final HashMap<String, String> result = new HashMap<>(); final NamedNodeMap atts = node.getAttributes(); for (int i = 0; i < atts.getLength(); i++) { final Node att = atts.item(i); result.put(att.getNodeName(), att.getNodeValue()); } return result; }
From source file:Main.java
public static String nodeToString(Node node) { String ret = "<null/>"; if (node != null) { ret = "<" + node.getNodeName() + " "; NamedNodeMap attrs = node.getAttributes(); if (attrs != null) { for (int i = 0; i < attrs.getLength(); i++) { Node attr = (Node) attrs.item(i); ret = ret + attr.getNodeName() + "='"; ret = ret + attr.getNodeValue() + "' "; }// w ww. j a v a2 s. co m } ret = ret + "/>"; } return ret; }
From source file:Main.java
public static void addAttribute(Document document, Node node, String attName, String attValue) { Attr attr = document.createAttribute(attName); attr.setNodeValue(removeXMLInvalidChars(attValue)); node.getAttributes().setNamedItem(attr); }