List of usage examples for org.w3c.dom Node getNodeName
public String getNodeName();
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 ww . j ava 2 s. co m } } } throw new IllegalArgumentException("No root node " + JBOSS_ESB + " found."); } else throw new IllegalArgumentException("Descriptor has no root element !"); }
From source file:Main.java
public static Element[] getChildren(Element parent, String name) { ArrayList<Element> al = new ArrayList<Element>(); NodeList nl = parent.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node n = nl.item(i); if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equals(name)) { al.add((Element) n);/*w w w. j a v a 2 s . c o m*/ } } return al.toArray(new Element[0]); }
From source file:Main.java
public static Element[] getChildrenByName(Element e, String name) { NodeList nl = e.getChildNodes(); int max = nl.getLength(); LinkedList<Node> list = new LinkedList<Node>(); for (int i = 0; i < max; i++) { Node n = nl.item(i); if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equals(name)) { list.add(n);//from ww w .j a va2 s . com } } return list.toArray(new Element[list.size()]); }
From source file:Main.java
/** * The method nodeList2Map transforms a list into a node. The method only * works properly if there are no duplicate nodes (nodes with the same * tagname)./* w ww . j a v a 2 s.co m*/ * * @param someNodes * a list of nodes * * @return a map containing all nodes */ static Map<String, Node> nodeList2Map(List<Node> someNodes) { Map<String, Node> map = new HashMap<String, Node>(); for (Node node : someNodes) { String tagname = node.getNodeName(); map.put(tagname, node); } return map; }
From source file:Main.java
public static List<Node> getMatchingChildNodes(Node node, String str, String str2, List<String> list) { if (node == null || str == null) { return null; }//from ww w . ja v a 2 s . c om List<Node> arrayList = new ArrayList(); NodeList childNodes = node.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node item = childNodes.item(i); if (item.getNodeName().equals(str) && nodeMatchesAttributeFilter(item, str2, list)) { arrayList.add(item); } } return arrayList; }
From source file:Main.java
private static boolean equalElements(final Element a, final Element b) { if (!a.getTagName().equals(b.getTagName())) { return false; }/* www .j a va 2 s.c o m*/ final NamedNodeMap attributes = a.getAttributes(); int customAttributeCounter = 0; for (int i = 0, n = attributes.getLength(); i < n; i++) { final Node node = attributes.item(i); if (node != null && !node.getNodeName().startsWith("_")) { if (!node.getNodeName().equals("z") && (b.getAttribute(node.getNodeName()).length() == 0 || !b.getAttribute(node.getNodeName()).equals(node.getNodeValue()))) { return false; } } else { customAttributeCounter++; } } if (a.getAttributes().getLength() - customAttributeCounter != b.getAttributes().getLength()) { return false; } return true; }
From source file:Main.java
/** * Dumps a debug listing of the attributes of the given element to * System.out.//w w w . j a va 2 s . co m * * @param elem the element to dump the attributes of */ public static void dumpAttrs(Element elem) { System.out.println("Attributes of " + elem.getNodeName() + ", NS: " + elem.getNamespaceURI()); NamedNodeMap attrs = elem.getAttributes(); int len = attrs.getLength(); for (int i = 0; i < len; ++i) { Node attr = attrs.item(i); System.out.println(" Name: " + attr.getNodeName() + ", Value: " + attr.getNodeValue() + ", NS: " + attr.getNamespaceURI()); } }
From source file:Main.java
public static List<Node> getChildrenByTagName(Node parent, String tagName) { List<Node> eleList = new ArrayList<Node>(); NodeList nodeList = parent.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equalsIgnoreCase(tagName)) { eleList.add(node);/* w ww . ja v a 2s.c om*/ } } return eleList; }
From source file:Main.java
/** * Returns the first child element found with the specified tag name * @param node The node to search// w ww.j a v a 2 s . c o m * @param element The element tag name to search for * @return The matching element Node */ public synchronized static Node getFirstElementIgnoreCase(Node node, String element) { if (node != null && element != null) { NodeList nl = node.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node n = nl.item(i); if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equalsIgnoreCase(element)) { return n; } } } return null; }
From source file:Main.java
/** * This method creates a map of all of the childern of a node * @param root - Parent node//ww w . ja v a2 s . c om * @return HashMap key value map of the children of the parent node */ public static HashMap getMap(Node root) { HashMap map = new HashMap(); if (root != null) { NodeList children = root.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); String nodeName = child.getNodeName(); if (!nodeName.equalsIgnoreCase("#comment") && !nodeName.equalsIgnoreCase("#text")) { if (child.getChildNodes().getLength() > 1) { map.put(nodeName, child); } else { Node textChild = child.getFirstChild(); if (textChild == null) { map.put(nodeName, null); } else { map.put(nodeName, child.getFirstChild().getNodeValue()); } } } } } return map; }