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
private static void traverseAttributes(JsonObject childJson, Node childNode) { NamedNodeMap attrNodeMap = childNode.getAttributes(); for (int j = 0; j < attrNodeMap.getLength(); j++) { Node attrNode = attrNodeMap.item(j); childJson.addProperty("-" + attrNode.getNodeName(), attrNode.getNodeValue()); }/*from ww w . ja va 2s .c om*/ }
From source file:Main.java
private static void serializeAttributeOf(XmlSerializer serializer, Element element) throws IOException { NamedNodeMap map = element.getAttributes(); for (int i = 0; i < map.getLength(); i++) { Node attr = map.item(i); serializer.attribute(null, attr.getNodeName(), attr.getNodeValue()); }// ww w .jav a 2 s.c o m }
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()); }/*w w w.j av a 2 s .c om*/ } if (tempNode.hasChildNodes()) { printNote(tempNode.getChildNodes(), depth + 1); } System.out.println(depth + "Node Name =" + tempNode.getNodeName()); } } }
From source file:Main.java
public static void edit(Document doc) { Element element = doc.getDocumentElement(); Element element2 = doc.createElement("newname"); NamedNodeMap attrs = element.getAttributes(); for (int i = 0; i < attrs.getLength(); i++) { Attr attr2 = (Attr) doc.importNode(attrs.item(i), true); element2.getAttributes().setNamedItem(attr2); }/*from ww w . ja v a2 s. c om*/ while (element.hasChildNodes()) { element2.appendChild(element.getFirstChild()); } element.getParentNode().replaceChild(element2, element); }
From source file:Main.java
public static String getAttributeValue(Element start, String attrName) { if (start.getNodeType() == Element.ELEMENT_NODE) { NamedNodeMap startAttr = start.getAttributes(); for (int i = 0; i < startAttr.getLength(); i++) { Node attr = startAttr.item(i); if (attrName.equals(attr.getNodeName().trim())) return attr.getNodeValue().trim(); }/*w w w . ja v a2s. c om*/ return null; } else return null; }
From source file:Main.java
public static List<Node> listize(final NamedNodeMap nnm) { return new AbstractList<Node>() { public Node get(int i) { return nnm.item(i); }/* w w w . j a v a 2s. c o m*/ public int size() { return nnm.getLength(); } }; }
From source file:Main.java
public static HashMap<String, String> getNodeAttributesMap(Node node) { HashMap<String, String> map = new HashMap<String, String>(); NamedNodeMap namedNodeMap = node.getAttributes(); for (int i = 0; i < namedNodeMap.getLength(); i++) { Node attribute = namedNodeMap.item(i); map.put(attribute.getNodeName(), attribute.getNodeValue()); }//from w w w.ja v a2 s . c om return map; }
From source file:Main.java
public static String getNamespaceURI(Document doc, String ns) { NamedNodeMap attr = doc.getDocumentElement().getAttributes(); for (int i = 0; i < attr.getLength(); i++) { Node attrNode = attr.item(i); if (attrNode.getNodeName().indexOf(ns) != -1) { return (attrNode.getNodeValue()); }/*from w w w. j a va 2 s . c o m*/ } return null; }
From source file:Main.java
public static String getNamespaceURI(final Document doc, final String ns) { NamedNodeMap attr = doc.getDocumentElement().getAttributes(); for (int i = 0; i < attr.getLength(); i++) { Node attrNode = attr.item(i); if (attrNode.getNodeName().indexOf(ns) != -1) { return (attrNode.getNodeValue()); }//w ww . j av a 2 s . co m } return null; }
From source file:Main.java
private static void transferAttributes(Element elm, Element elm2) { NamedNodeMap attributes = elm.getAttributes(); for (int c = 0; c < attributes.getLength(); c++) { Attr attr = (Attr) attributes.item(c); elm2.setAttributeNodeNS((Attr) elm2.getOwnerDocument().importNode(attr, true)); }/*from w w w. ja v a 2s . c o m*/ }