/***** Code de MesExemples.com *******/ import org.w3c.dom.Document;import org.apache.xerces.dom.DOMImplementation;import org.w3c.dom.Element;public class MainClass { public static void main(String args[]) { Document dom = DOMImplementation.createDocument(null, null, null); Element root = dom.createElement("games"); Element child1 = dom.createElement("game"); root.appendChild(child1); dom.appendChild(root); }} |
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 xerces: Analyser un document XML avec SAX
{filelink=8705} /***** Code de MesExemples.com *******/ import org.apache.xerces.parsers.SAXParser; import org.xml.sax.InputSource; import java.io.FileInputStream; public class MainClass { public static void main(String args[]) throws Exception { SAXParser …
-
Java xerces: Utilisation de XMLSerializer pour sérialiser la sortie
{filelink=8704} /***** Code de MesExemples.com *******/ import org.w3c.dom.Document;import org.apache.xerces.dom.DOMImplementation;import org.w3c.dom.Element;import org.apache.xml.serialize.XMLSerializer;import java.io.IOException;public class MainClass { public static void main(String args[]) throws IOException { Document dom = DOMImplementation.createDocument(null, null, null); Element root = dom.createElement(“A”); Element child1 = dom.createElement(“B”); child1.appendChild(dom.createTextNode(“C”)); child1.setAttribute(“A”, “a”); root.appendChild(child1); dom.appendChild(root); XMLSerializer serial = new XMLSerializer(System.out, null); serial.serialize(dom.getDocumentElement()); }} Code testé avec le fichier XML Suivant Sakoba Adams Rappel Ne m’oubliez pas ce week-end!
-
Javascript: Ajouter une semaine à la date actuelle avec getTime()
{filelink=3992} function nextWeek() { var todayInMS = today.getTime(); // Obtenir la date en milliseconde // Ajouter l’équivalent d’une semaine en milliseconde à la date actuelle …
-
Java XML: Ajouter un texte dans un élément XML
{filelink=8418} /***** Code de MesExemples.com *******/ import org.w3c.dom.Document; import org.w3c.dom.Element; public class ExempleXMLTExt { public static void addText(Element element, String text) { element.appendChild(element.getOwnerDocument().createTextNode(text)); } } …
-
Java: Exemple d’utilisation d’une collection pour les énumérateurs avec EnumSet
{filelink=23} /** * @(#)ExempleEnumSet.java * Exemple d’utilisation d’une collection pour les énumérateurs avec EnumSet * * @author *sakoba(java.mesexemples.com) @version 1.00 2012/11/29 */ import java.util.*; public …
-
Java PDF: Ajouter des signets avec des contours dans un document PDF
{filelink=10344} /***** Code de MesExemples.com *******/ import java.io.FileOutputStream; import com.itextpdf.text.Document; import com.itextpdf.text.Font; import com.itextpdf.text.PageSize; import com.itextpdf.text.Paragraph; import com.itextpdf.text.pdf.PdfContentByte; import com.itextpdf.text.pdf.PdfDestination; import com.itextpdf.text.pdf.PdfOutline; import com.itextpdf.text.pdf.PdfPageEventHelper; import …
-
Javascript: Ajouter un titre à une table
{filelink=3583} function addTitle(){ var x=document.getElementById(‘myTable’).createCaption() x.innerHTML=”Ma table des capitales” } A B Paris Londre Madrid Berlin
-
Javascript: Ajouter un titre à une table
{filelink=3583} function addTitle(){ var x=document.getElementById(‘myTable’).createCaption() x.innerHTML=”Ma table des capitales” } A B Paris Londre Madrid Berlin
-
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
-
Java: Ajouter un commentaire au début d’un document
{filelink=8410} /***** Code de MesExemples.com *******/ /** * @(#)AddCommentToDoc.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.NodeList; import …
-
Java: Joindre ou ajouter une donnée dans un objet ‘CharacterData’
{filelink=8336} /***** Code de MesExemples.com *******/ /** * @(#)AppendCharacerData.java * * * @author *sakoba(java.mesexemples.com) @version 1.00 2013/7/4 */ import java.io.File; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.CDATASection; import …
-
Java: Afficher un vecteur à l’aide d’un Iterator
{filelink=23} /** * @(#)AffichageVecteurIterator.java * * * @author *sakoba(java.mesexemples.com) @version 1.00 2012/11/23 */ import java.util.*; public class AffichageVecteurIterator { public static void main (String[] args) …
-
Java XML: Créer un document XML avec des nœuds, éléments, attributs et commentaires
{filelink=8387} /***** Code de MesExemples.com *******/ /** * @(#)CreerDocXML.java * * * @author *sakoba(java.mesexemples.com) @version 1.00 2013/7/4 */ import java.io.FileOutputStream; import java.io.IOException; import javax.xml.parsers.DocumentBuilder; import …
-
Ajouter heures, minutes ou secondes à une date
{filelink=5567} import java.util.Calendar; public class CalendarOperation { public static void main(String[] args) { Calendar maintenant = Calendar.getInstance(); System.out.println(“Date actuelle = ” + maintenant.getTime()); // Soustraire …
-
Java-source: Ajouter un Bouton dans une Applet
{filelink=613} /***** Code de MesExemples.com *******/ import javax.swing.JApplet; import javax.swing.JButton; import java.awt.Font; public class applet extends JApplet { public void init() { // créer des …
Cet article Java xerces: ajouter un élément avec DOM est apparu en premier sur .