/***** Code de MesExemples.com *******/ /** * @(#)CopieXMLDoc.java * * * @author *sakoba(java.mesexemples.com) @version 1.00 2013/7/4 */ import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; public class CopieXMLDoc { // Utiliser le document source comme le fils du neud principal du document de destination public static void copiperDocument(Document source, Document destination) { Node node = destination.importNode(source.getDocumentElement(), true); destination.getDocumentElement().appendChild(node); } } |
Code testé avec le fichier XML Suivant
<?xml version="1.0" encoding="windows-1252"?> <!-- Edited by MesEXemple.com --> <note> <to>Sakoba</to> <from>Adams</from> <heading>Rappel</heading> <body>Ne m'oubliez pas ce week-end!</body> </note> |
A Voir sur le même Sujet
-
Java: Copier les sous-arborescences de nœuds d’un document DOM vers un autre
{filelink=8547} /***** Code de MesExemples.com *******/ /** * @(#)XMLSubTreeFromDocToDoc.java * * * @author *sakoba(java.mesexemples.com) @version 1.00 2013/7/5 */ import java.io.File; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; import …
-
Java NIO: Copier un fichier
{filelink=22} import java.io.*; import java.nio.*; import java.nio.channels.*; public class NIOCopier { public static void main(String[] args) throws IOException { String in_File=”c:/test.txt”; String out_File=”c:/test2.txt”; copier(in_File,out_File); } …
-
Wildcard: Copier le contenu d’une liste dans une autre
{filelink=12227} import java.util.ArrayList; import java.util.List; import java.util.Arrays; public class Generic_Wildcard { // La fonction copie une liste d’objet dans une autre public static void copier(List
-
Java: Copier le contenu d’un Fichier dans un autre
{filelink=23} /** * @(#)JavaFileCopier.java * * * @author * @version 1.00 2013/8/24 */ import java.io.*; import java.nio.*; import java.nio.channels.*; public class JavaFileCopier { public JavaFileCopier() …
-
Collection: Copier les éléments d’une ArrayList dans une autre
{filelink=4856} import java.util.ArrayList; import java.util.Collections; public class Ex_ArrayL { public static void main(String[] args) { ArrayList array_L1 = new ArrayList(); array_L1.add(“1”); array_L1.add(“2”); array_L1.add(“3”); ArrayList array_L2 …
-
Java: Copier et Coller sur un JTextArea
{filelink=23} private void copier(JTextArea txt) { try { String str=txt.getText(); Toolkit toolkit = Toolkit.getDefaultToolkit(); Clipboard clipboard = toolkit.getSystemClipboard(); StringSelection strSel = new StringSelection(str); clipboard.setContents(strSel, null); …
-
Java: Copier et Coller sur un JTextPane
{filelink=23} private void copier(JTextPane txt) { try { String str=txt.getText(); Toolkit toolkit = Toolkit.getDefaultToolkit(); Clipboard clipboard = toolkit.getSystemClipboard(); StringSelection strSel = new StringSelection(str); clipboard.setContents(strSel, null); …
-
Copier les éléments d’un ‘ArrayList’ dans un Vecteur
{filelink=4855} import java.util.ArrayList; import java.util.Collections; import java.util.Vector; public class ArrayListToVec { public static void main(String[] args) { // Création d’un ArrayList ArrayList arrayList = new …
-
Exemple d’utilisation de ‘Arrays.copyof’ pour copier un tableau
{filelink=820} import java.util.Arrays; public class ExempleArrayCopy { public static void main(String args[]) { System.out.printf(“Valeur Initiale (Tableau original)\t%s%n”, Arrays.toString(args)); // Copier le contenu du tableau “args” …
-
Copier le contenu d’un Stream dans un Autre
{filelink=4621} import java.io.*; class CopierStream { /** * Copier un Stream dans un autre * On utilise les classes abstraites * ‘InputStream’ et ‘OutputStream’ * …
-
Java: Copier une arborescence source vers une une arborescnce destination*
{filelink=8415} /***** Code de MesExemples.com *******/ import org.w3c.dom.Attr;import org.w3c.dom.DOMException;import org.w3c.dom.Document;import org.w3c.dom.Element;import org.w3c.dom.NamedNodeMap;import org.w3c.dom.Node;import com.sun.org.apache.xerces.internal.dom.AttrImpl;import com.sun.org.apache.xerces.internal.dom.DocumentImpl;/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the “License”); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an “AS IS” BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */public class Main { /** * Copies the source tree into the specified place in a destination * tree. The source node and its children are appended as children * of the destination node. * * Note: This is an iterative implementation. */ public static void copyInto(Node src, Node dest) throws DOMException { // get node factory Document factory = dest.getOwnerDocument(); boolean domimpl = factory instanceof DocumentImpl; // placement variables Node start = src; Node parent = src; Node place = src; // traverse source tree while (place != null) { // copy this node Node node = null; int type = place.getNodeType(); switch (type) { case Node.CDATA_SECTION_NODE: { node = factory.createCDATASection(place.getNodeValue()); break; } case Node.COMMENT_NODE: { node = factory.createComment(place.getNodeValue()); break; } case Node.ELEMENT_NODE: { Element element = factory.createElement(place.getNodeName()); node = element; NamedNodeMap attrs = place.getAttributes(); int attrCount = attrs.getLength(); for (int i = 0; i
-
Javascript-DOM: Modifier un document
{filelink=77} document.onclick=changeDoc; function changeDoc( ) { // Suppression des éléments var hdr = document.getElementById(“myHeadee”); var div = document.getElementById(“div1”); div.removeChild(hdr); // Remplacer l’image par texte var …
-
Java PDF: Démarrer une nouvelle page
{filelink=10498} /***** Code de MesExemples.com *******/ /** * @(#)StartNewPagePDF.java * * * @author *sakoba(java.mesexemples.com) @version 1.00 2013/4/30 */ import java.io.FileOutputStream; import com.itextpdf.text.Chunk; import com.itextpdf.text.Document; import …
-
Java PDF: Modifier la version d’un document PDF
{filelink=10563} /***** Code de MesExemples.com *******/ /** * @(#)PDFVersion.java * * * @author *sakoba(java.mesexemples.com) @version 1.00 2013/5/29 */ import java.io.FileOutputStream; import com.itextpdf.text.Document; import com.itextpdf.text.Paragraph; import …
-
Java PDF: Créer des liens entre des document PDF
{filelink=10437} /***** Code de MesExemples.com *******/ /** * @(#)ConnexionDocumentPDF.java * * * @author *sakoba(java.mesexemples.com) @version 1.00 2013/4/30 */ import java.io.FileOutputStream; import com.itextpdf.text.Chunk; import com.itextpdf.text.Document; import …
Cet article Java: Copier un document XML est apparu en premier sur .