List of usage examples for org.w3c.dom NamedNodeMap item
public Node item(int index);
index
th item in the map. From source file:Main.java
public static void getNamespaces(Node node, Map<String, String> list) { NamedNodeMap atts = node.getAttributes(); for (int i = 0; i < atts.getLength(); i++) { Node n = atts.item(i); if ("xmlns".equals(n.getNodeName())) { list.put(n.getNodeName(), n.getNodeValue()); } else {/*from w w w . j a va 2 s.c om*/ if (n.getNodeName().startsWith("xmlns:")) { list.put(n.getNodeName().substring(6), n.getNodeValue()); } } } }
From source file:Main.java
public static void dumpNodeDetails(Node node) throws Exception { NamedNodeMap attributes = node.getAttributes(); for (int t = 0; t < attributes.getLength(); t++) { Node aNode = attributes.item(t); log.info("aName = " + aNode.getNodeName() + " : aValue = " + aNode.getNodeValue()); }/*from w w w .j a va 2 s .c o m*/ }
From source file:Main.java
private static void clearAttributes(Node node) { final NamedNodeMap attributes = node.getAttributes(); while (attributes.getLength() > 0) { attributes.removeNamedItem(attributes.item(0).getNodeName()); }//from www . j a v a 2 s . com }
From source file:Main.java
/** * Returns all attributes of the given XML node as a list of name=value strings. * Mostly just for debugging.//from ww w . ja v a 2 s . c o m * @param node * @return */ public static List<String> getAttributes(Node node) { List<String> result = new ArrayList<String>(); NamedNodeMap attrs = node.getAttributes(); for (int i = 0; i < attrs.getLength(); i++) { Node attrNode = attrs.item(i); result.add(attrNode.getNodeName() + "=" + attrNode.getNodeValue()); } return result; }
From source file:Utils.java
public static void copyAttributes(Element from, Element to) { NamedNodeMap attributes = from.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Attr node = (Attr) attributes.item(i); to.setAttributeNS(node.getNamespaceURI(), node.getName(), node.getValue()); }/* w w w . ja v a 2 s.c o m*/ }
From source file:Main.java
public static String lookupNamespaceURI(Node root, String specifiedPrefix) { if (root == null) { return null; }/*from ww w . j a v a 2s. c o m*/ if (root.hasAttributes()) { NamedNodeMap nnm = root.getAttributes(); for (int i = 0; i < nnm.getLength(); i++) { Node n = nnm.item(i); if (("xmlns".equals(n.getPrefix()) && specifiedPrefix.equals(n.getNodeName())) || ("xmlns:" + specifiedPrefix).equals(n.getNodeName())) { return n.getNodeValue(); } } } return lookupNamespaceURI(root.getParentNode(), specifiedPrefix); }
From source file:Main.java
private static void addAttrDirect(Map<String, Object> values, Element el) { NamedNodeMap attrs = el.getAttributes(); for (int i = 0; i < attrs.getLength(); i++) { Node attr = attrs.item(i); values.put(attr.getNodeName(), attr.getNodeValue()); }// w w w.j ava 2 s. co m }
From source file:Main.java
public static Object getPropertyValue(Element element) { NamedNodeMap map = element.getAttributes(); map.removeNamedItem(NAME_ATTR);//from w ww. j av a2s .c o m if (map.item(0).getNodeName().equals(STRING_ATTR)) return map.item(0).getNodeValue(); else if (map.item(0).getNodeName().equals(INTEGER_ATTR)) return new Integer(map.item(0).getNodeValue()); else if (map.item(0).getNodeName().equals(DOUBLE_ATTR)) return new Double(map.item(0).getNodeValue()); else if (map.item(0).getNodeName().equals(FLOAT_ATTR)) return new Float(map.item(0).getNodeValue()); else if (map.item(0).getNodeName().equals(BOOLEAN_ATTR)) return Boolean.valueOf(map.item(0).getNodeValue()); else if (map.item(0).getNodeName().equals(COLOR_ATTR)) { String[] rgb = map.item(0).getNodeValue().split(","); return new Color(new Integer(rgb[0]), new Integer(rgb[1]), new Integer(rgb[2])); } else if (map.item(0).getNodeName().equals(FONT_ATTR)) { String[] font = map.item(0).getNodeValue().split(","); return new Font(font[0], new Integer(font[1]), new Integer(font[2])); } else { return null; } }
From source file:Main.java
private static int countNonNamespaceAttribures(NamedNodeMap attrs) { int n = 0;//w ww. jav a 2 s .co m for (int i = 0; i < attrs.getLength(); i++) { Attr attr = (Attr) attrs.item(i); if (!attr.getName().startsWith("xmlns")) { n++; } } return n; }
From source file:Main.java
public static Object getPropertyValue(Element element) { NamedNodeMap map = element.getAttributes(); map.removeNamedItem(NAME_ATTR);// w w w.j a va 2s. co m if (map.item(0).getNodeName().equals(STRING_ATTR)) { return map.item(0).getNodeValue(); } else if (map.item(0).getNodeName().equals(INTEGER_ATTR)) { return new Integer(map.item(0).getNodeValue()); } else if (map.item(0).getNodeName().equals(DOUBLE_ATTR)) { return new Double(map.item(0).getNodeValue()); } else if (map.item(0).getNodeName().equals(FLOAT_ATTR)) { return new Float(map.item(0).getNodeValue()); } else if (map.item(0).getNodeName().equals(BOOLEAN_ATTR)) { return Boolean.valueOf(map.item(0).getNodeValue()); } else if (map.item(0).getNodeName().equals(COLOR_ATTR)) { String[] rgb = map.item(0).getNodeValue().split(","); return new Color(new Integer(rgb[0]), new Integer(rgb[1]), new Integer(rgb[2])); } else if (map.item(0).getNodeName().equals(FONT_ATTR)) { String[] font = map.item(0).getNodeValue().split(","); return new Font(font[0], new Integer(font[1]), new Integer(font[2])); } else { return null; } }