List of usage examples for org.w3c.dom NamedNodeMap getLength
public int getLength();
From source file:Main.java
public static void copyAttr(Element from, Element to) { NamedNodeMap nnm = from.getAttributes(); for (int i = 0; i < nnm.getLength(); ++i) { String name = nnm.item(i).getNodeName(); if (!to.hasAttribute(name)) { String value = nnm.item(i).getNodeValue(); to.setAttribute(name, value); }// w w w. j ava 2 s . c o m } }
From source file:Main.java
public static String getAttribute(Node node, String name) { NamedNodeMap attr = node.getAttributes(); for (int n = 0; n < attr.getLength(); n++) { Node attribute = attr.item(n); if (attribute.getNodeName().equals(name)) return attribute.getNodeValue(); }//from w ww. j a v a2s . co m return ""; }
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()); }//from ww w. j ava 2 s. c o m }
From source file:Main.java
public static HashMap<String, String> getEleAttrNameValueMap(Element ele) { HashMap<String, String> ht = new HashMap<String, String>(); NamedNodeMap nnm = ele.getAttributes(); int len = nnm.getLength(); Node tmpn = null;/*w w w . j a va 2s .c om*/ for (int k = 0; k < len; k++) { tmpn = nnm.item(k); String tmps = tmpn.getNodeValue(); if (tmps == null) { tmps = ""; } ht.put(tmpn.getNodeName(), tmps); } return ht; }
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()); }// ww w. ja va 2 s .c o m }
From source file:Main.java
public static void copyAttributes(Node from, Node to) { NamedNodeMap map = from.getAttributes(); for (int i = 0; i < map.getLength(); i++) { Node attr = map.item(i);//from w ww .ja va2 s .c om addAttribute(to, attr.getNodeName(), attr.getNodeValue()); } }
From source file:Main.java
/** * get attribute map from the element/*from ww w. j a v a 2s . c o m*/ * @param el - element * @return mapping of attributes */ public static Map<String, String> getAttributes(Element el) { Map<String, String> list = new LinkedHashMap<String, String>(); NamedNodeMap map = el.getAttributes(); for (int i = 0; i < map.getLength(); i++) { list.put(map.item(i).getNodeName(), map.item(i).getNodeValue()); } return list; }
From source file:Main.java
public static String getPrefix(org.w3c.dom.Element el, String ns) { NamedNodeMap atts = el.getAttributes(); for (int i = 0; i < atts.getLength(); i++) { Node node = atts.item(i); String name = node.getNodeName(); if (ns.equals(node.getNodeValue()) && (name != null && (XMLNAMESPACE.equals(name) || name.startsWith(XMLNAMESPACE + ":")))) { return node.getPrefix(); }/* w ww . jav a2s . co m*/ } return null; }
From source file:Main.java
private static void printNote(NodeList nodeList, int depth) { for (int count = 0; count < nodeList.getLength(); count++) { Node tempNode = nodeList.item(count); if (tempNode.getNodeType() == Node.ELEMENT_NODE) { System.out.println(depth + "Node Name =" + tempNode.getNodeName()); System.out.println(depth + "Node Value =" + tempNode.getTextContent()); if (tempNode.hasAttributes()) { NamedNodeMap nodeMap = tempNode.getAttributes(); for (int i = 0; i < nodeMap.getLength(); i++) { Node node = nodeMap.item(i); System.out.println("attr name : " + node.getNodeName()); System.out.println("attr value : " + node.getNodeValue()); }//from w ww. ja v a2s .c o m } if (tempNode.hasChildNodes()) { printNote(tempNode.getChildNodes(), depth + 1); } System.out.println(depth + "Node Name =" + tempNode.getNodeName()); } } }
From source file:Main.java
public static void removeAttributes(Element element) { NamedNodeMap namedNodeMap = element.getAttributes(); while (namedNodeMap.getLength() > 0) { element.removeAttributeNode((Attr) namedNodeMap.item(0)); }/*from w w w. j a v a2 s. co m*/ }