/** override insertChild. * if newNode has parent detach()es first * @param newNode * @param pos */ public void insertChild(Node newNode, int pos) { newNode.detach(); super.insertChild(newNode, pos); }
public static void deleteNode(Document doc , String entityType, String entityName) { Node node = getNode(doc, entityType, entityName); if (node != null) { node.detach(); } }
/** remove all arg childern from element. * * @param element to remove args from */ public static void removeArgs(CMLElement element) { if (element != null) { List<Node> args = CMLUtil.getQueryNodes(element, CMLArg.NS, CMLConstants.CML_XPATH); for (Node arg : args) { arg.detach(); } } }
public void moveChildrenTo(Element element) { for (Node childNode : getChildNodes()) { childNode.detach(); element.xomElement.appendChild(childNode); } }
private void copyNodesBeforeBodyIntoHead(Element html, Element head) { for (Node child : nodesBeforeBody(html)) { child.detach(); head.appendChild(child); } }
public void moveChildrenTo(Element element) { for (Node childNode : getChildNodes()) { childNode.detach(); element.xomElement.appendChild(childNode); } }
private void copyNodesBeforeBodyIntoHead(Element html, Element head) { for (Node child : nodesBeforeBody(html)) { child.detach(); head.appendChild(child); } }
/** override replaceChild. * @param oldNode * @param newNode */ public void replaceChild(Node oldNode, Node newNode) { int pos = this.indexOf(oldNode); if (pos == -1) { throw new RuntimeException("Cannot replace non-child"); } newNode.detach(); this.removeChild(oldNode); this.insertChild(newNode, pos); }
/** * <p> * Appends a node to the children of this node. * </p> * * @param child node to append to this node * * @throws IllegalAddException if this node cannot have children * of this type * @throws NullPointerException if <code>child</code> is null * */ public void appendChild(Node child) { // if (child instanceof CMLArray) { // CMLUtil.debug((Element)child, "CHILLLL000"); // } child.detach(); int childCount = this.getChildCount(); insertChild(child, childCount); // if (child instanceof CMLArray) { // CMLUtil.debug((Element)child, "CHILLLL111"); // } }
/** * remeoves all whitespace-only text nodes. * * @param element * to strip whitespace from */ public static void removeWhitespaceNodes(Element element) { int nChild = element.getChildCount(); List<Node> nodeList = new ArrayList<Node>(); for (int i = 0; i < nChild; i++) { Node node = element.getChild(i); if (node instanceof Text) { if (node.getValue().trim().length() == 0) { nodeList.add(node); } } else if (node instanceof Element) { Element childElement = (Element) node; removeWhitespaceNodes(childElement); } else { } } for (Node node : nodeList) { node.detach(); } }
/** replace current element by its child nodes. * does not work for root node * */ public void replaceByChildren() { Node parent = this.getParent(); if (parent == null) { } else if (!(parent instanceof Element)) { } else { Element parentElement = (Element) parent; int idx = parentElement.indexOf(this); List<Node> nodeList = new ArrayList<Node>(); for (int i = 0; i < this.getChildCount(); i++) { nodeList.add(this.getChild(i)); } for (int i = 0; i < nodeList.size(); i++) { Node node = nodeList.get(i); node.detach(); parentElement.insertChild(node, idx + i); } } this.detach(); } /**
private Nodes transformMatch(Element elem) { // if (DEBUG) System.err.println("found match at level=" + level + ":" // + XOMUtil.toPrettyXML(elem)); level--; if (transform == null) return super.finishMakingElement(elem); Nodes results = transform.transform(elem); // prevent potential nu.xom.MultipleParentException by detaching for (int i = results.size(); --i >= 0; ) { Node node = results.get(i); if (node != elem) node.detach(); } return results; }
private Nodes transformMatch(Element elem) { // if (DEBUG) System.err.println("found match at level=" + level + ":" // + XOMUtil.toPrettyXML(elem)); level--; if (transform == null) return super.finishMakingElement(elem); Nodes results = transform.transform(elem); // prevent potential nu.xom.MultipleParentException by detaching for (int i = results.size(); --i >= 0; ) { Node node = results.get(i); if (node != elem) node.detach(); } return results; }
/** * transfers children of 'from' to 'to'. * * @param from * (will be left with no children) * @param to * (will gain 'from' children appended after any existing * children */ public static void transferChildren(Element from, Element to) { int nc = from.getChildCount(); int tc = to.getChildCount(); for (int i = nc - 1; i >= 0; i--) { Node child = from.getChild(i); child.detach(); to.insertChild(child, tc); } }
public void normalizeFormulas() { CMLFormula formula = new CMLFormula(this); String concise = formula.getConcise(); Nodes formulaElements = this.query("./cml:formula", CML_XPATH); for (int i = 0; i < formulaElements.size(); i++) { CMLFormula formulaElement = (CMLFormula) formulaElements.get(i); String conciseString = formulaElement.getConcise(); if (conciseString == null) { formulaElement.setConcise(concise); } else if (conciseString.equals(concise)) { // no need to update } else { throw new RuntimeException("incompatible concise formulae; was "+ conciseString+"; now "+concise); } // remove any spurious atomArrays Nodes atomArrays = formulaElement.query("./cml:atomArray", CML_XPATH); for (int j = 0; j < atomArrays.size(); j++) { atomArrays.get(j).detach(); } } }
this.setInline(content); for (int i = 0; i < texts.size(); i++) { texts.get(i).detach();