List of usage examples for org.w3c.dom Element getNextSibling
public Node getNextSibling();
From source file:Utils.java
public static Element getNextElement(Element el) { Node nd = el.getNextSibling(); while (nd != null) { if (nd.getNodeType() == Node.ELEMENT_NODE) { return (Element) nd; }// w w w .ja v a 2 s . com nd = nd.getNextSibling(); } return null; }
From source file:Main.java
/** * Returns next sibling element node// w w w .j ava2s . com * @param element * @return */ protected static Element getNextSiblingElement(Element element) { try { Node tmpNode = null; tmpNode = element.getNextSibling(); while (tmpNode.getNodeType() != Node.ELEMENT_NODE) { //fix for structure that has more than two parents null if (tmpNode.getNextSibling() == null) tmpNode = tmpNode.getParentNode(); tmpNode = tmpNode.getNextSibling(); } return (Element) tmpNode; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:Main.java
/** * Get the next sibling element of the specified element, null if it has no other siblings. * //from www . j a va2s. c o m * @param element The element to search siblings for. * @return The next sibling element, null if it has none. */ public static Element getNextSibling(Element element) { if (element == null) return null; Node node = element.getNextSibling(); while (node != null) { if (node.getNodeType() == Node.ELEMENT_NODE) return (Element) node; node = node.getNextSibling(); } return null; }
From source file:Main.java
public static Element getNextSiblingElement(Element elem) { if (elem == null) { return null; }// w ww . j a va 2 s. co m for (Node n = elem.getNextSibling(); n != null; n = n.getNextSibling()) { if (n.getNodeType() == Node.ELEMENT_NODE) { return (Element) n; } } return null; }
From source file:Main.java
/** * Get the next sibling element./*from w w w .j a v a 2 s . c om*/ * * @param element - an Element object. * @return the next sibling element. */ public static Element getNextSibling(Element element) { // Return next sibling element return findNextSibling(element.getNextSibling()); }
From source file:Main.java
public static void edit(Document doc) { NodeList list = doc.getElementsByTagName("name"); Element element = (Element) list.item(0); Element dup = (Element) element.cloneNode(true); element.getParentNode().insertBefore(dup, element.getNextSibling()); }
From source file:ListMoviesXML.java
private static Movie getMovie(Element e) { String yearString = e.getAttribute("year"); int year = Integer.parseInt(yearString); Element tElement = (Element) e.getFirstChild(); String title = getTextValue(tElement).trim(); Element pElement = (Element) tElement.getNextSibling(); String pString = getTextValue(pElement).trim(); double price = Double.parseDouble(pString); return new Movie(title, year, price); }
From source file:Main.java
/** * Get the next sibling element with the given name. This differs from {@link * org.w3c.dom.Node#getNextSibling Node.getNextSibling} in that this only returns elements. * * @param node the current node for which to get the next sibling * @param name the name of the next sibling element to get; may be null or "*" to indicate the * next sibling of any name * @return the sibling, or null if none was found *///from w ww.java2 s. co m public static Element getNextSibling(Element node, String name) { final String filter = (name != null && !name.equals("*")) ? name : null; for (Node n = node.getNextSibling(); n != null; n = n.getNextSibling()) { if (n.getNodeType() == Node.ELEMENT_NODE && (filter == null || n.getNodeName().equals(filter))) return (Element) n; } return null; }
From source file:Main.java
/** * Converts the document from namespace-qualified form into unqualified form by removing all * namespace information./*from w w w . j av a 2 s . c o m*/ * * @param document the document to convert */ public static void convertFromNamespaceForm(final Document document) { final Element oldRootElement = document.getDocumentElement(); if (oldRootElement != null) { final Node nodeAfterRootElement = oldRootElement.getNextSibling(); final Node newRootElement = convertFromNamespaceForm(oldRootElement); document.removeChild(oldRootElement); document.insertBefore(newRootElement, nodeAfterRootElement); } }
From source file:Main.java
/** * Returns the next sibling Element for an element, optionally matching tag names. * /*from w w w.j ava 2 s .c om*/ * @param child the element from which to search for a next sibling * @param sameName true to retrive the next sibling element of the same name, of false if any name is allowed * @return the next sibling element if one exists, or null otherwise */ static public Element getNextSiblingElement(Element child, boolean sameName) { // Child Element suchen if (child == null) return null; String name = child.getTagName(); Node node = child.getNextSibling(); while (node != null) { // Find all Element nodes if (node.getNodeType() == Node.ELEMENT_NODE) { // check name Element elem = (Element) node; if (sameName && name.equalsIgnoreCase(elem.getTagName())) return elem; // found } node = node.getNextSibling(); } return null; // not found! }