org.w3c.dom.Element.replaceChild()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(255)

本文整理了Java中org.w3c.dom.Element.replaceChild()方法的一些代码示例,展示了Element.replaceChild()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.replaceChild()方法的具体详情如下:
包路径:org.w3c.dom.Element
类名称:Element
方法名:replaceChild

Element.replaceChild介绍

暂无

代码示例

代码示例来源:origin: osmandapp/Osmand

  1. protected static void copyAndReplaceElement(Element oldElement, Element newElement) {
  2. while(oldElement.getChildNodes().getLength() > 0) {
  3. newElement.appendChild(oldElement.getChildNodes().item(0));
  4. }
  5. NamedNodeMap attrs = oldElement.getAttributes();
  6. for(int i = 0; i < attrs.getLength(); i++) {
  7. Node ns = attrs.item(i);
  8. newElement.setAttribute(ns.getNodeName(), ns.getNodeValue());
  9. }
  10. ((Element)oldElement.getParentNode()).replaceChild(newElement, oldElement);
  11. }
  12. }

代码示例来源:origin: scouter-project/scouter

  1. /**
  2. * Add object type to custom counter xml (if exist replace it)
  3. * @param objType
  4. * @return success or not
  5. */
  6. public synchronized boolean safelyAddObjectType(ObjectType objType) {
  7. initUnsafeDoc();
  8. if (unsafeDoc == null) {
  9. return false;
  10. }
  11. Element newElement = unsafeDoc.createElement(CounterEngine.TAG_OBJECT_TYPE);
  12. setObjectTypeAttribute(unsafeDoc, newElement, objType);
  13. Element oldElement = findElementByTypeAndName(CounterEngine.TAG_OBJECT_TYPE, objType.getName());
  14. Element typesElements = (Element) unsafeDoc.getElementsByTagName(CounterEngine.TAG_TYPES).item(0);
  15. if (oldElement == null) {
  16. typesElements.appendChild(newElement);
  17. } else {
  18. typesElements.replaceChild(newElement, oldElement);
  19. }
  20. saveCustomContent();
  21. return true;
  22. }

代码示例来源:origin: aragozin/jvm-tools

  1. head.replaceChild(re, e);
  2. importCss(href, re);

代码示例来源:origin: scouter-project/scouter

  1. familiesElement.appendChild(newElement);
  2. } else {
  3. familiesElement.replaceChild(newElement, oldElement);

代码示例来源:origin: nodebox/nodebox

  1. @Override
  2. public void apply(Element e) {
  3. if (e.getTagName().equals("property")) {
  4. Element parent = (Element) e.getParentNode();
  5. if (parent != null && parent.getTagName().equals("ndbx")) {
  6. Attr name = e.getAttributeNode("name");
  7. Attr value = e.getAttributeNode("value");
  8. if (name != null && name.getValue().equals("oscPort")) {
  9. if (value != null) {
  10. Element device = e.getOwnerDocument().createElement("device");
  11. device.setAttribute("name", "osc1");
  12. device.setAttribute("type", "osc");
  13. Element portProperty = e.getOwnerDocument().createElement("property");
  14. portProperty.setAttribute("name", "port");
  15. portProperty.setAttribute("value", value.getValue());
  16. device.appendChild(portProperty);
  17. Element autostartProperty = e.getOwnerDocument().createElement("property");
  18. autostartProperty.setAttribute("name", "autostart");
  19. autostartProperty.setAttribute("value", "true");
  20. device.appendChild(autostartProperty);
  21. parent.replaceChild(device, e);
  22. } else {
  23. parent.removeChild(e);
  24. }
  25. }
  26. }
  27. }
  28. }
  29. }

代码示例来源:origin: camunda/camunda-bpm-platform

  1. public void replaceChild(DomElement newChildDomElement, DomElement existingChildDomElement) {
  2. synchronized(document) {
  3. Element newElement = ((DomElementImpl) newChildDomElement).getElement();
  4. Element existingElement = ((DomElementImpl) existingChildDomElement).getElement();
  5. try {
  6. element.replaceChild(newElement, existingElement);
  7. }
  8. catch (DOMException e) {
  9. throw new ModelException("Unable to replace child <" + existingElement + "> of element <" + element + "> with element <" + newElement + ">", e);
  10. }
  11. }
  12. }

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-j2ee-clientproject

  1. private static Element updateMinAntVersion (final Element root, final Document doc) {
  2. NodeList list = root.getElementsByTagNameNS (AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE,MINIMUM_ANT_VERSION_ELEMENT);
  3. if (list.getLength() == 1) {
  4. Element me = (Element) list.item(0);
  5. list = me.getChildNodes();
  6. if (list.getLength() == 1) {
  7. me.replaceChild (doc.createTextNode(AppClientProjectGenerator.MINIMUM_ANT_VERSION), list.item(0));
  8. return root;
  9. }
  10. }
  11. assert false : "Invalid project file"; //NOI18N
  12. return root;
  13. }

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-j2ee-ejbjarproject

  1. private static Element updateMinAntVersion (final Element root, final Document doc) {
  2. NodeList list = root.getElementsByTagNameNS (EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,MINIMUM_ANT_VERSION_ELEMENT);
  3. if (list.getLength() == 1) {
  4. Element me = (Element) list.item(0);
  5. list = me.getChildNodes();
  6. if (list.getLength() == 1) {
  7. me.replaceChild (doc.createTextNode(EjbJarProjectGenerator.MINIMUM_ANT_VERSION), list.item(0));
  8. return root;
  9. }
  10. }
  11. assert false : "Invalid project file"; //NOI18N
  12. return root;
  13. }

代码示例来源:origin: org.opensingular/singular-commons

  1. /**
  2. * @see org.w3c.dom.Node#replaceChild(Node, Node)
  3. */
  4. public Node replaceChild(Node arg0, Node arg1) throws DOMException {
  5. return getCurrentInternal().replaceChild(arg0, arg1);
  6. }

代码示例来源:origin: Geomatys/geotoolkit

  1. @Override
  2. public Node replaceChild(Node newChild, Node oldChild) throws DOMException {
  3. final Element elem = getElement();
  4. return elem != null ? elem.replaceChild(newChild, oldChild) : null;
  5. }

代码示例来源:origin: org.opensingular/form-core

  1. /**
  2. * @see org.w3c.dom.Node#replaceChild(Node, Node)
  3. */
  4. public Node replaceChild(Node arg0, Node arg1) throws DOMException {
  5. return getAtualInterno().replaceChild(arg0, arg1);
  6. }

代码示例来源:origin: com.rackspace.apache/xerces2-xsd11

  1. /**
  2. * Perform general override transformations on <override> element
  3. * replace current element with the new override element
  4. *
  5. */
  6. private Element performDOMOverride(Element overridenSchemaRoot,Element overrideNode, Element oldNode) {
  7. Element clonedNode = (Element)getChildClone(overrideNode);
  8. overridenSchemaRoot.replaceChild(clonedNode,oldNode);
  9. return clonedNode;
  10. }

代码示例来源:origin: org.xmlbeam/xmlprojector

  1. /**
  2. * @param previous
  3. * @param newNode
  4. */
  5. public static void replaceElement(final Element previous, final Element newNode) {
  6. assert previous.getParentNode() != null;
  7. Element parent = (Element) previous.getParentNode();
  8. Document document = DOMHelper.getOwnerDocumentFor(parent);
  9. DOMHelper.ensureOwnership(document, newNode);
  10. parent.replaceChild(newNode, previous);
  11. }

代码示例来源:origin: org.apache.ws.commons.axiom/dom-testsuite

  1. protected void runTest(Document doc, Node newChild) {
  2. Element parent = doc.createElementNS(null, "parent");
  3. Element oldChild = doc.createElementNS(null, "oldChild");
  4. parent.appendChild(oldChild);
  5. parent.replaceChild(newChild, oldChild);
  6. assertSame(newChild, parent.getFirstChild());
  7. assertSame(newChild, parent.getLastChild());
  8. NodeList children = parent.getChildNodes();
  9. assertEquals(1, children.getLength());
  10. assertSame(newChild, children.item(0));
  11. }
  12. }

代码示例来源:origin: org.w3c.jigsaw/jigsaw

  1. public void setResourceType(String type) {
  2. Document doc = element.getOwnerDocument();
  3. Node rtn = DAVNode.getDAVNode(element, RESOURCETYPE_NODE);
  4. Element rtype = DAVFactory.createDAVElement(doc, RESOURCETYPE_NODE);
  5. if (type != null) {
  6. DAVNode.addDAVNode(rtype, type, null);
  7. }
  8. if (rtn != null) {
  9. element.replaceChild(rtype, rtn);
  10. } else {
  11. element.appendChild(rtype);
  12. }
  13. }

代码示例来源:origin: org.opensingular/singular-commons

  1. /**
  2. * @see org.w3c.dom.Node#replaceChild(Node, Node)
  3. */
  4. @Override
  5. public Node replaceChild(Node arg0, Node arg1) {
  6. return original.get().replaceChild(EWrapper.getOriginal(arg0), arg1);
  7. }

代码示例来源:origin: org.opensingular/form-core

  1. /**
  2. * @see org.w3c.dom.Node#replaceChild(Node, Node)
  3. */
  4. @Override
  5. public Node replaceChild(Node arg0, Node arg1) {
  6. if (arg0 instanceof MElementWrapper) {
  7. arg0 = ((MElementWrapper) arg0).original.get();
  8. }
  9. return original.get().replaceChild(arg0, arg1);
  10. }

代码示例来源:origin: org.camunda.bpm.model/camunda-xml-model

  1. public void replaceChild(DomElement newChildDomElement, DomElement existingChildDomElement) {
  2. synchronized(document) {
  3. Element newElement = ((DomElementImpl) newChildDomElement).getElement();
  4. Element existingElement = ((DomElementImpl) existingChildDomElement).getElement();
  5. try {
  6. element.replaceChild(newElement, existingElement);
  7. }
  8. catch (DOMException e) {
  9. throw new ModelException("Unable to replace child <" + existingElement + "> of element <" + element + "> with element <" + newElement + ">", e);
  10. }
  11. }
  12. }

代码示例来源:origin: org.seamless/seamless-xml

  1. public CHILD replaceChild(CHILD original, CHILD replacement, boolean copy) {
  2. replacement = adoptOrImport(getW3CElement().getOwnerDocument(), replacement, copy);
  3. getW3CElement().replaceChild(replacement.getW3CElement(), original.getW3CElement());
  4. return replacement;
  5. }

代码示例来源:origin: com.js-lib/js-dom

  1. @Override
  2. public Element replaceChild(Element replacement, Element existing) {
  3. Params.notNull(replacement, "Replacement element");
  4. Params.notNull(existing, "Exiting element");
  5. if (replacement.getDocument() != ownerDoc) {
  6. replacement = ownerDoc.importElement(replacement);
  7. }
  8. node.replaceChild(node(replacement), node(existing));
  9. return this;
  10. }

相关文章