org.dom4j.Node.detach()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(6.4k)|赞(0)|评价(0)|浏览(444)

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

Node.detach介绍

[英]Removes this node from its parent if there is one. If this node is the root element of a document then it is removed from the document as well.

This method is useful if you want to remove a node from its source document and add it to another document. For example
Node node = ...; Element someOtherElement = ...; someOtherElement.add( node.detach() );
[中]如果存在父节点,则将其从父节点中移除。如果此节点是文档的根元素,则它也将从文档中删除。
如果要从源文档中删除节点并将其添加到另一个文档中,此方法非常有用。例如
Node node = ...; Element someOtherElement = ...; someOtherElement.add( node.detach() );

代码示例

代码示例来源:origin: igniterealtime/Openfire

  1. ((Node) iter.next()).detach();

代码示例来源:origin: jenkinsci/jenkins

  1. root.addText(o.toString());
  2. } else {
  3. root.add(((org.dom4j.Node)o).detach());

代码示例来源:origin: alibaba/PelicanDT

  1. @Override
  2. public void deleteNode(Node node) {
  3. if (null == node) {
  4. log.warn("The node to be deleted is null, operation skip!");
  5. } else {
  6. node.detach();
  7. }
  8. }

代码示例来源:origin: org.hibernate/com.springsource.org.hibernate

  1. public void setToXMLNode(Node node, Object value, SessionFactoryImplementor factory)
  2. throws HibernateException {
  3. if ( !isEmbeddedInXML ) {
  4. node.detach();
  5. }
  6. else {
  7. replaceNode( node, (Element) value );
  8. }
  9. }

代码示例来源:origin: org.hibernate/com.springsource.org.hibernate.core

  1. public void setToXMLNode(Node node, Object value, SessionFactoryImplementor factory)
  2. throws HibernateException {
  3. if ( !isEmbeddedInXML ) {
  4. node.detach();
  5. }
  6. else {
  7. replaceNode( node, (Element) value );
  8. }
  9. }

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

  1. public void setToXMLNode(Node node, Object value, SessionFactoryImplementor factory)
  2. throws HibernateException {
  3. if ( !isEmbeddedInXML ) {
  4. node.detach();
  5. }
  6. else {
  7. replaceNode( node, (Element) value );
  8. }
  9. }

代码示例来源:origin: jboss.jboss-embeddable-ejb3/hibernate-all

  1. public void setToXMLNode(Node node, Object value, SessionFactoryImplementor factory)
  2. throws HibernateException {
  3. if ( !isEmbeddedInXML ) {
  4. node.detach();
  5. }
  6. else {
  7. replaceNode( node, (Element) value );
  8. }
  9. }

代码示例来源:origin: stackoverflow.com

  1. Node node = ...;
  2. Element someOtherElement = ...;
  3. someOtherElement.add( node.detach() );

代码示例来源:origin: stackoverflow.com

  1. @Test
  2. public void dom4j() throws DocumentException, IOException {
  3. String absolutePath = Paths.get(PATH_TO_XML).toAbsolutePath().toString();
  4. SAXReader reader = new SAXReader();
  5. Document document = reader.read(absolutePath);
  6. Node node = document.selectSingleNode(XPATH_TO_NODE);
  7. node.detach();
  8. XMLWriter writer = new XMLWriter(new FileWriter(absolutePath), OutputFormat.createPrettyPrint());
  9. writer.write(document);
  10. writer.close();
  11. }

代码示例来源:origin: com.societegenerale.ci-droid/extensions

  1. @Override
  2. public String provideContent(String documentToProcess, ResourceToUpdate resourceToUpdate) throws IssueProvidingContentException {
  3. Document originalDocument = parseStringIntoDocument(documentToProcess);
  4. List<Node> elementUnderXpathWeLookFor = originalDocument.selectNodes(xpathElementToRemove);
  5. if (elementUnderXpathWeLookFor.isEmpty()) {
  6. log.info(xpathElementToRemove + " didn't match any element - not removing any element");
  7. return documentToProcess;
  8. }
  9. elementUnderXpathWeLookFor.stream().forEach(e -> e.detach());
  10. return prettyPrint(originalDocument);
  11. }

代码示例来源:origin: org.igniterealtime.openfire/xmppserver

  1. ((Node) iter.next()).detach();

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

  1. protected static void replaceNode(Node container, Element value) {
  2. if ( container!=value ) { //not really necessary, I guess...
  3. Element parent = container.getParent();
  4. container.detach();
  5. value.setName( container.getName() );
  6. value.detach();
  7. parent.add(value);
  8. }
  9. }

代码示例来源:origin: jboss.jboss-embeddable-ejb3/hibernate-all

  1. protected static void replaceNode(Node container, Element value) {
  2. if ( container!=value ) { //not really necessary, I guess...
  3. Element parent = container.getParent();
  4. container.detach();
  5. value.setName( container.getName() );
  6. value.detach();
  7. parent.add(value);
  8. }
  9. }

代码示例来源:origin: org.hibernate/com.springsource.org.hibernate.core

  1. protected static void replaceNode(Node container, Element value) {
  2. if ( container!=value ) { //not really necessary, I guess...
  3. Element parent = container.getParent();
  4. container.detach();
  5. value.setName( container.getName() );
  6. value.detach();
  7. parent.add(value);
  8. }
  9. }

代码示例来源:origin: org.hibernate/com.springsource.org.hibernate

  1. protected static void replaceNode(Node container, Element value) {
  2. if ( container!=value ) { //not really necessary, I guess...
  3. Element parent = container.getParent();
  4. container.detach();
  5. value.setName( container.getName() );
  6. value.detach();
  7. parent.add(value);
  8. }
  9. }

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

  1. if (!(node instanceof Element)) {
  2. node.detach();
  3. } else {

代码示例来源:origin: com.atlassian.bamboo.plugins.dotnet/atlassian-bamboo-plugin-dotnet

  1. StreamSource source = new StreamSource(inputStream);
  2. Document newDocument = DocumentFactory.getInstance().createDocument();
  3. newDocument.add(run.detach());
  4. try

代码示例来源:origin: org.cogchar/org.cogchar.lib.convoid

  1. ArrayList<Node> nodesCopy = new ArrayList<Node>(nodes);
  2. for (Node n : nodesCopy) {
  3. n.detach();
  4. System.out.println("Copying node: " + n);
  5. stepElement.add(n);

代码示例来源:origin: org.alfresco.surf/spring-surf

  1. /**
  2. * <p>Deleting an {@link ExtensionModule} is a two stage process. First it is necessary to locate the
  3. * {@link ExtensionModule} in the {@link List} and then remove it if it is present. Secondly it is necessary
  4. * to update the {@link Document} maintained by the {@link ExtensionImpl}.</p>
  5. *
  6. * @param moduleId String
  7. * @return ExtensionModule
  8. */
  9. public ExtensionModule deleteExtensionModule(String moduleId)
  10. {
  11. ExtensionModule targetModule = null;
  12. Document extensionDocument = getDocument();
  13. ModuleObjectAndNode moan = findModule(moduleId, extensionDocument);
  14. if (moan != null)
  15. {
  16. if (moan.getObject() != null)
  17. {
  18. getExtensionModules().remove(moan.getObject());
  19. targetModule = moan.getObject();
  20. }
  21. if (moan.getNode() != null)
  22. {
  23. moan.getNode().detach();
  24. this.updateXML(extensionDocument);
  25. }
  26. }
  27. return targetModule;
  28. }

代码示例来源:origin: org.springframework.extensions.surf/spring-surf

  1. /**
  2. * <p>Deleting an {@link ExtensionModule} is a two stage process. First it is necessary to locate the
  3. * {@link ExtensionModule} in the {@link List} and then remove it if it is present. Secondly it is necessary
  4. * to update the {@link Document} maintained by the {@link ExtensionImpl}.</p>
  5. *
  6. * @param moduleId String
  7. * @return ExtensionModule
  8. */
  9. public ExtensionModule deleteExtensionModule(String moduleId)
  10. {
  11. ExtensionModule targetModule = null;
  12. Document extensionDocument = getDocument();
  13. ModuleObjectAndNode moan = findModule(moduleId, extensionDocument);
  14. if (moan != null)
  15. {
  16. if (moan.getObject() != null)
  17. {
  18. getExtensionModules().remove(moan.getObject());
  19. targetModule = moan.getObject();
  20. }
  21. if (moan.getNode() != null)
  22. {
  23. moan.getNode().detach();
  24. this.updateXML(extensionDocument);
  25. }
  26. }
  27. return targetModule;
  28. }

相关文章