本文整理了Java中org.w3c.dom.Node.replaceChild()
方法的一些代码示例,展示了Node.replaceChild()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Node.replaceChild()
方法的具体详情如下:
包路径:org.w3c.dom.Node
类名称:Node
方法名:replaceChild
[英]Replaces the child node oldChild
with newChild
in the list of children, and returns the oldChild
node.
If newChild
is a DocumentFragment
object, oldChild
is replaced by all of the DocumentFragment
children, which are inserted in the same order. If the newChild
is already in the tree, it is first removed.
Note: Replacing a node with itself is implementation dependent.
[中]将子节点oldChild
替换为子节点列表中的newChild
,并返回oldChild
节点。
如果newChild
是DocumentFragment
对象,oldChild
将被所有DocumentFragment
子对象替换,这些子对象按相同顺序插入。如果newChild
已在树中,则首先将其删除。
注意:用节点本身替换节点取决于实现。
代码示例来源:origin: pmd/pmd
@Override
public org.w3c.dom.Node replaceChild(org.w3c.dom.Node newChild, org.w3c.dom.Node oldChild) throws DOMException {
return node.replaceChild(newChild, oldChild);
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
protected boolean replaceNode(Node[] primaryNodes, Node testNode, List<Node> usedNodes) {
boolean foundItem = false;
for (int j=0;j<primaryNodes.length;j++){
if (primaryNodes[j].getNodeName().equals(testNode.getNodeName())) {
Node newNode = primaryNodes[j].getOwnerDocument().importNode(testNode.cloneNode(true), true);
primaryNodes[j].getParentNode().replaceChild(newNode, primaryNodes[j]);
usedNodes.add(testNode);
foundItem = true;
}
}
return foundItem;
}
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
protected boolean replaceNode(Node[] primaryNodes, Node testNode, final String attribute, List<Node> usedNodes) {
if (testNode.getAttributes().getNamedItem(attribute) == null) {
return false;
}
Node[] filtered = NodeUtil.filterByAttribute(primaryNodes, attribute);
int pos = NodeUtil.findNode(filtered, testNode, attribute, true);
if (pos >= 0) {
Node foundNode = filtered[pos];
Node newNode = foundNode.getOwnerDocument().importNode(testNode.cloneNode(true), true);
foundNode.getParentNode().replaceChild(newNode, foundNode);
usedNodes.add(testNode);
return true;
}
return false;
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
filtered[pos].getParentNode().replaceChild(newNode, filtered[pos]);
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
Node newTestNode = foundNode.getOwnerDocument().importNode(testNode.cloneNode(true), true);
NodeUtil.mergeNodeLists(targetNode, newTestNode.getChildNodes(), foundNode.getChildNodes(), "name");
foundNode.getParentNode().replaceChild(targetNode, foundNode);
usedNodes.add(testNode);
return true;
代码示例来源:origin: org.apache.poi/poi-ooxml
@Override
public void postSign(Document document)
throws MarshalException {
// check for XAdES-BES
NodeList nl = document.getElementsByTagNameNS(XADES_132_NS, "QualifyingProperties");
if (nl.getLength() != 1) {
throw new MarshalException("no XAdES-BES extension present");
}
QualifyingPropertiesType qualProps;
try {
qualProps = QualifyingPropertiesType.Factory.parse(nl.item(0), DEFAULT_XML_OPTIONS);
} catch (XmlException e) {
throw new MarshalException(e);
}
// create basic XML container structure
UnsignedPropertiesType unsignedProps = qualProps.getUnsignedProperties();
if (unsignedProps == null) {
unsignedProps = qualProps.addNewUnsignedProperties();
}
UnsignedSignaturePropertiesType unsignedSigProps = unsignedProps.getUnsignedSignatureProperties();
if (unsignedSigProps == null) {
/* unsignedSigProps = */ unsignedProps.addNewUnsignedSignatureProperties();
}
Node n = document.importNode(qualProps.getDomNode().getFirstChild(), true);
nl.item(0).getParentNode().replaceChild(n, nl.item(0));
}
}
代码示例来源:origin: apache/geode
root.replaceChild(newNode, node);
nodeAdded = true;
break;
root.replaceChild(newNode, node);
nodeAdded = true;
break;
代码示例来源:origin: org.apache.poi/poi-ooxml
qualNl.item(0).getParentNode().replaceChild(n, qualNl.item(0));
代码示例来源:origin: camunda/camunda-bpm-platform
/**
* Recursively apply includes through all SQL fragments.
* @param source Include node in DOM tree
* @param variablesContext Current context for static variables with values
*/
private void applyIncludes(Node source, final Properties variablesContext, boolean included) {
if (source.getNodeName().equals("include")) {
Node toInclude = findSqlFragment(getStringAttribute(source, "refid"), variablesContext);
Properties toIncludeContext = getVariablesContext(source, variablesContext);
applyIncludes(toInclude, toIncludeContext, true);
if (toInclude.getOwnerDocument() != source.getOwnerDocument()) {
toInclude = source.getOwnerDocument().importNode(toInclude, true);
}
source.getParentNode().replaceChild(toInclude, source);
while (toInclude.hasChildNodes()) {
toInclude.getParentNode().insertBefore(toInclude.getFirstChild(), toInclude);
}
toInclude.getParentNode().removeChild(toInclude);
} else if (source.getNodeType() == Node.ELEMENT_NODE) {
NodeList children = source.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
applyIncludes(children.item(i), variablesContext, included);
}
} else if (included && source.getNodeType() == Node.TEXT_NODE
&& !variablesContext.isEmpty()) {
// replace variables ins all text nodes
source.setNodeValue(PropertyParser.parse(source.getNodeValue(), variablesContext));
}
}
代码示例来源:origin: org.mybatis/mybatis
toInclude = source.getOwnerDocument().importNode(toInclude, true);
source.getParentNode().replaceChild(toInclude, source);
while (toInclude.hasChildNodes()) {
toInclude.getParentNode().insertBefore(toInclude.getFirstChild(), toInclude);
代码示例来源:origin: spring-projects/spring-roo
XmlUtils.findFirstElement(
"//*[@id='" + child.getAttribute("id") + "']", proposed);
proposedElementToReplace.getParentNode().replaceChild(
proposed.getOwnerDocument().importNode(child, false),
proposedElementToReplace);
originalElement.getParentNode().replaceChild(
original.getOwnerDocument().importNode(proposedElement, false),
originalElement);
代码示例来源:origin: elki-project/elki
@Override
public void run() {
prev.getParentNode().replaceChild(newe, prev);
// Note: no warning if it is not possible!
}
}
代码示例来源:origin: io.fabric8/fabric-utils
/**
* Replaces the old node with the new node
*/
public static void replaceWith(Node oldNode, Node newNode) {
Node parentNode = oldNode.getParentNode();
if (parentNode != null) {
parentNode.replaceChild(newNode, oldNode);
}
}
代码示例来源:origin: elki-project/elki
/**
* Update style element - invoke this appropriately after any change to the
* CSS styles.
*/
public void updateStyleElement() {
// TODO: this should be sufficient - why does Batik occasionally not pick up
// the changes unless we actually replace the style element itself?
// cssman.updateStyleElement(document, style);
Element newstyle = cssman.makeStyleElement(document);
style.getParentNode().replaceChild(newstyle, style);
style = newstyle;
}
代码示例来源:origin: de.lmu.ifi.dbs.elki/elki-batik-visualization
/**
* Update style element - invoke this appropriately after any change to the
* CSS styles.
*/
public void updateStyleElement() {
// TODO: this should be sufficient - why does Batik occasionally not pick up
// the changes unless we actually replace the style element itself?
// cssman.updateStyleElement(document, style);
Element newstyle = cssman.makeStyleElement(document);
style.getParentNode().replaceChild(newstyle, style);
style = newstyle;
}
代码示例来源:origin: elki-project/elki
@Override
public void run() {
Element olde = plot.getIdElement(id);
if(olde != null) {
olde.getParentNode().replaceChild(newe, olde);
plot.putIdElement(id, newe);
}
// Note: no warning if it is not possible!
}
}
代码示例来源:origin: errai/errai
@Override
public boolean replaceNode(final XPathExpression expression, final Node replacement)
throws XPathExpressionException {
assertOpen();
final Node node = getNodeByXPath(expression);
if (node != null) {
final Node parent = node.getParentNode();
parent.replaceChild(replacement, node);
return (modified = true);
}
return false;
}
代码示例来源:origin: org.n52.security/52n-security-core
public XMLBuilder replaceNodeAt(String xpath, XMLElement element) {
Node target = find(xpath);
target.getParentNode().replaceChild(element.toW3C(), target);
return this;
}
代码示例来源:origin: de.lmu.ifi.dbs.elki/elki-batik-visualization
@Override
public void run() {
Element olde = plot.getIdElement(id);
if(olde != null) {
olde.getParentNode().replaceChild(newe, olde);
plot.putIdElement(id, newe);
}
// Note: no warning if it is not possible!
}
}
代码示例来源:origin: org.vx68k.quercus/quercus
public DOMNode replaceChild(DOMNode newChild, DOMNode oldChild)
throws DOMException
{
try {
return wrap(_delegate.replaceChild(
newChild.getDelegate(), oldChild.getDelegate()));
}
catch (org.w3c.dom.DOMException ex) {
throw wrap(ex);
}
}
内容来源于网络,如有侵权,请联系作者删除!