protected static void copyAndReplaceElement(Element oldElement, Element newElement) { while(oldElement.getChildNodes().getLength() > 0) { newElement.appendChild(oldElement.getChildNodes().item(0)); } NamedNodeMap attrs = oldElement.getAttributes(); for(int i = 0; i < attrs.getLength(); i++) { Node ns = attrs.item(i); newElement.setAttribute(ns.getNodeName(), ns.getNodeValue()); } ((Element)oldElement.getParentNode()).replaceChild(newElement, oldElement); } }
/** * Add object type to custom counter xml (if exist replace it) * @param objType * @return success or not */ public synchronized boolean safelyAddObjectType(ObjectType objType) { initUnsafeDoc(); if (unsafeDoc == null) { return false; } Element newElement = unsafeDoc.createElement(CounterEngine.TAG_OBJECT_TYPE); setObjectTypeAttribute(unsafeDoc, newElement, objType); Element oldElement = findElementByTypeAndName(CounterEngine.TAG_OBJECT_TYPE, objType.getName()); Element typesElements = (Element) unsafeDoc.getElementsByTagName(CounterEngine.TAG_TYPES).item(0); if (oldElement == null) { typesElements.appendChild(newElement); } else { typesElements.replaceChild(newElement, oldElement); } saveCustomContent(); return true; }
head.replaceChild(re, e); importCss(href, re);
familiesElement.appendChild(newElement); } else { familiesElement.replaceChild(newElement, oldElement);
@Override public void apply(Element e) { if (e.getTagName().equals("property")) { Element parent = (Element) e.getParentNode(); if (parent != null && parent.getTagName().equals("ndbx")) { Attr name = e.getAttributeNode("name"); Attr value = e.getAttributeNode("value"); if (name != null && name.getValue().equals("oscPort")) { if (value != null) { Element device = e.getOwnerDocument().createElement("device"); device.setAttribute("name", "osc1"); device.setAttribute("type", "osc"); Element portProperty = e.getOwnerDocument().createElement("property"); portProperty.setAttribute("name", "port"); portProperty.setAttribute("value", value.getValue()); device.appendChild(portProperty); Element autostartProperty = e.getOwnerDocument().createElement("property"); autostartProperty.setAttribute("name", "autostart"); autostartProperty.setAttribute("value", "true"); device.appendChild(autostartProperty); parent.replaceChild(device, e); } else { parent.removeChild(e); } } } } } }
public void replaceChild(DomElement newChildDomElement, DomElement existingChildDomElement) { synchronized(document) { Element newElement = ((DomElementImpl) newChildDomElement).getElement(); Element existingElement = ((DomElementImpl) existingChildDomElement).getElement(); try { element.replaceChild(newElement, existingElement); } catch (DOMException e) { throw new ModelException("Unable to replace child <" + existingElement + "> of element <" + element + "> with element <" + newElement + ">", e); } } }
private static Element updateMinAntVersion (final Element root, final Document doc) { NodeList list = root.getElementsByTagNameNS (AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE,MINIMUM_ANT_VERSION_ELEMENT); if (list.getLength() == 1) { Element me = (Element) list.item(0); list = me.getChildNodes(); if (list.getLength() == 1) { me.replaceChild (doc.createTextNode(AppClientProjectGenerator.MINIMUM_ANT_VERSION), list.item(0)); return root; } } assert false : "Invalid project file"; //NOI18N return root; }
private static Element updateMinAntVersion (final Element root, final Document doc) { NodeList list = root.getElementsByTagNameNS (EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,MINIMUM_ANT_VERSION_ELEMENT); if (list.getLength() == 1) { Element me = (Element) list.item(0); list = me.getChildNodes(); if (list.getLength() == 1) { me.replaceChild (doc.createTextNode(EjbJarProjectGenerator.MINIMUM_ANT_VERSION), list.item(0)); return root; } } assert false : "Invalid project file"; //NOI18N return root; }
/** * @see org.w3c.dom.Node#replaceChild(Node, Node) */ public Node replaceChild(Node arg0, Node arg1) throws DOMException { return getCurrentInternal().replaceChild(arg0, arg1); }
@Override public Node replaceChild(Node newChild, Node oldChild) throws DOMException { final Element elem = getElement(); return elem != null ? elem.replaceChild(newChild, oldChild) : null; }
/** * @see org.w3c.dom.Node#replaceChild(Node, Node) */ public Node replaceChild(Node arg0, Node arg1) throws DOMException { return getAtualInterno().replaceChild(arg0, arg1); }
/** * Perform general override transformations on <override> element * replace current element with the new override element * */ private Element performDOMOverride(Element overridenSchemaRoot,Element overrideNode, Element oldNode) { Element clonedNode = (Element)getChildClone(overrideNode); overridenSchemaRoot.replaceChild(clonedNode,oldNode); return clonedNode; }
/** * @param previous * @param newNode */ public static void replaceElement(final Element previous, final Element newNode) { assert previous.getParentNode() != null; Element parent = (Element) previous.getParentNode(); Document document = DOMHelper.getOwnerDocumentFor(parent); DOMHelper.ensureOwnership(document, newNode); parent.replaceChild(newNode, previous); }
protected void runTest(Document doc, Node newChild) { Element parent = doc.createElementNS(null, "parent"); Element oldChild = doc.createElementNS(null, "oldChild"); parent.appendChild(oldChild); parent.replaceChild(newChild, oldChild); assertSame(newChild, parent.getFirstChild()); assertSame(newChild, parent.getLastChild()); NodeList children = parent.getChildNodes(); assertEquals(1, children.getLength()); assertSame(newChild, children.item(0)); } }
public void setResourceType(String type) { Document doc = element.getOwnerDocument(); Node rtn = DAVNode.getDAVNode(element, RESOURCETYPE_NODE); Element rtype = DAVFactory.createDAVElement(doc, RESOURCETYPE_NODE); if (type != null) { DAVNode.addDAVNode(rtype, type, null); } if (rtn != null) { element.replaceChild(rtype, rtn); } else { element.appendChild(rtype); } }
/** * @see org.w3c.dom.Node#replaceChild(Node, Node) */ @Override public Node replaceChild(Node arg0, Node arg1) { return original.get().replaceChild(EWrapper.getOriginal(arg0), arg1); }
/** * @see org.w3c.dom.Node#replaceChild(Node, Node) */ @Override public Node replaceChild(Node arg0, Node arg1) { if (arg0 instanceof MElementWrapper) { arg0 = ((MElementWrapper) arg0).original.get(); } return original.get().replaceChild(arg0, arg1); }
public void replaceChild(DomElement newChildDomElement, DomElement existingChildDomElement) { synchronized(document) { Element newElement = ((DomElementImpl) newChildDomElement).getElement(); Element existingElement = ((DomElementImpl) existingChildDomElement).getElement(); try { element.replaceChild(newElement, existingElement); } catch (DOMException e) { throw new ModelException("Unable to replace child <" + existingElement + "> of element <" + element + "> with element <" + newElement + ">", e); } } }
public CHILD replaceChild(CHILD original, CHILD replacement, boolean copy) { replacement = adoptOrImport(getW3CElement().getOwnerDocument(), replacement, copy); getW3CElement().replaceChild(replacement.getW3CElement(), original.getW3CElement()); return replacement; }
@Override public Element replaceChild(Element replacement, Element existing) { Params.notNull(replacement, "Replacement element"); Params.notNull(existing, "Exiting element"); if (replacement.getDocument() != ownerDoc) { replacement = ownerDoc.importElement(replacement); } node.replaceChild(node(replacement), node(existing)); return this; }