public static void replaceChild(Parent parent, Node newChild, Node oldNode) { int idx = parent.nodeIndexOf(oldNode); if (idx < 0) { parent.addNode(newChild); } else { parent.removeNode(idx); parent.addNode(idx, newChild); } }
private void replace(Element what, Element with) { Parent parent = what.getParent(); int idx = parent.nodeIndexOf(what); what.remove(); parent.addNode(idx, with); }
private boolean replacePath(Element from, Parent to, String replacePath) { Element replace = to.getChild(replacePath); if (replace == null) { // if nothing to replace, then append it to parent int lastSlash = replacePath.lastIndexOf('/'); if (lastSlash == -1) { throw new IllegalStateException("Cannot replace path " + replacePath + " with " + name); } Parent p = to.getChild(replacePath.substring(0, lastSlash)); if (p == null) { throw new IllegalStateException("Cannot append/replace path " + replacePath + " with " + name); } p.addNode(cleanup(from.copy())); } else { replace(replace, cleanup(from.copy())); } return true; }
public void remove() { if( null == getParent() ) { return; } getParent().removeNode( this ); } }
public Element (Parent parent, String name, Namespace ns) { if (name == null) throw new NullPointerException ("name is null"); if (name.trim ().length () == 0) throw new IllegalArgumentException ("name is blank"); this.parent = parent; this.name = name; compactEmpty = true; setNamespace (ns); if (parent != null) parent.addNode (this); }
private boolean appendPath(Element from, Parent to, String appendPath) { Element append = to.getChild(appendPath); if (append == null) { throw new IllegalStateException("Cannot append " + name + " to path " + appendPath); } append.addNode(cleanup(from.copy())); return true; }
p.toXML (writer);
public Document getDocument () { Parent p = getParent (); while (p != null) { if (p.getType () == Type.DOCUMENT) return (Document)p; p = ((Child)p).getParent (); } return null; }
Parent grandParent = root.getParent(); if (grandParent != null) { grandParent.addNode(grandParent.nodeIndexOf(root), c); } else { LOG.warn("Cannot save the comment '{}' as there's no parent in the DOM", text);
private void processElem(Element from, Parent to) { String merge = from.getAttributeValue("merge"); if ("replace".equals(merge)) { // find first element by the same name and merge into that one Element other = to.getChild(from.getName()); if (other != null) { replace(other, cleanup(from.copy())); return; } } else if (Boolean.parseBoolean(merge)) { // find first element by the same name and merge into that one Element other = to.getChild(from.getName()); if (other != null) { merge(from, other); return; } } to.addNode(cleanup(from.copy())); }
public Document setRootNode (Element rootNode) { if (this.rootNode != null) { removeNode (this.rootNode); } this.rootNode = null; if (rootNode.getParent () != null) { rootNode.getParent ().removeNode (rootNode); } super.addNode (rootNode); return this; }
public Element getParentElement () { if (getParent () == null || getParent ().getType () == Type.DOCUMENT ) return null; return (Element)getParent (); }
public static void replaceChild(Parent parent, Node newChild, Node oldNode) { int idx = parent.nodeIndexOf(oldNode); if (idx < 0) { parent.addNode(newChild); } else { parent.removeNode(idx); parent.addNode(idx, newChild); } }
Parent grandParent = root.getParent(); if (grandParent != null) { grandParent.addNode(grandParent.nodeIndexOf(root), c); } else { LOG.warn("Cannot save the comment '{}' as there's no parent in the DOM", text);