本文整理了Java中org.w3c.dom.Element.replaceChild()
方法的一些代码示例,展示了Element.replaceChild()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.replaceChild()
方法的具体详情如下:
包路径:org.w3c.dom.Element
类名称:Element
方法名:replaceChild
暂无
代码示例来源:origin: osmandapp/Osmand
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);
}
}
代码示例来源:origin: scouter-project/scouter
/**
* 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;
}
代码示例来源:origin: aragozin/jvm-tools
head.replaceChild(re, e);
importCss(href, re);
代码示例来源:origin: scouter-project/scouter
familiesElement.appendChild(newElement);
} else {
familiesElement.replaceChild(newElement, oldElement);
代码示例来源:origin: nodebox/nodebox
@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);
}
}
}
}
}
}
代码示例来源:origin: camunda/camunda-bpm-platform
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);
}
}
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-j2ee-clientproject
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;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-j2ee-ejbjarproject
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;
}
代码示例来源:origin: org.opensingular/singular-commons
/**
* @see org.w3c.dom.Node#replaceChild(Node, Node)
*/
public Node replaceChild(Node arg0, Node arg1) throws DOMException {
return getCurrentInternal().replaceChild(arg0, arg1);
}
代码示例来源:origin: Geomatys/geotoolkit
@Override
public Node replaceChild(Node newChild, Node oldChild) throws DOMException {
final Element elem = getElement();
return elem != null ? elem.replaceChild(newChild, oldChild) : null;
}
代码示例来源:origin: org.opensingular/form-core
/**
* @see org.w3c.dom.Node#replaceChild(Node, Node)
*/
public Node replaceChild(Node arg0, Node arg1) throws DOMException {
return getAtualInterno().replaceChild(arg0, arg1);
}
代码示例来源:origin: com.rackspace.apache/xerces2-xsd11
/**
* 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;
}
代码示例来源:origin: org.xmlbeam/xmlprojector
/**
* @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);
}
代码示例来源:origin: org.apache.ws.commons.axiom/dom-testsuite
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));
}
}
代码示例来源:origin: org.w3c.jigsaw/jigsaw
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);
}
}
代码示例来源:origin: org.opensingular/singular-commons
/**
* @see org.w3c.dom.Node#replaceChild(Node, Node)
*/
@Override
public Node replaceChild(Node arg0, Node arg1) {
return original.get().replaceChild(EWrapper.getOriginal(arg0), arg1);
}
代码示例来源:origin: org.opensingular/form-core
/**
* @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);
}
代码示例来源:origin: org.camunda.bpm.model/camunda-xml-model
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);
}
}
}
代码示例来源:origin: org.seamless/seamless-xml
public CHILD replaceChild(CHILD original, CHILD replacement, boolean copy) {
replacement = adoptOrImport(getW3CElement().getOwnerDocument(), replacement, copy);
getW3CElement().replaceChild(replacement.getW3CElement(), original.getW3CElement());
return replacement;
}
代码示例来源:origin: com.js-lib/js-dom
@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;
}
内容来源于网络,如有侵权,请联系作者删除!