/***** 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 saxParser = new SAXParser(); saxParser.setContentHandler(new EventHandler()); saxParser.parse(new InputSource(new FileInputStream("games.xml"))); } } |
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: 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: Mise en forme des textes avec des fonctions de la classe String
{filelink=34} var texte = new String(“Apprendre javascript”); document.writeln(texte.big( )); document.writeln(texte.blink( )); document.writeln(texte.sup( )); document.writeln(texte.strike( )); document.writeln(texte.bold( )); document.writeln(texte.italics( )); document.writeln(texte.small( )); document.writeln(texte.link(‘http://www.mesexemples.com’));
-
Java: Exemple d’utilisation des code-barres avec PDF
{filelink=10332} /***** Code de MesExemples.com *******/ import java.io.FileOutputStream; import com.itextpdf.text.Document; import com.itextpdf.text.Image; import com.itextpdf.text.PageSize; import com.itextpdf.text.pdf.BarcodePDF417; import com.itextpdf.text.pdf.PdfWriter; public class CodeBarrePDF { public static void …
-
Java PDF: Modifier la police et la rotation avec setSkew()
{filelink=10364} /***** Code de MesExemples.com *******/ /** * @(#)ExempleSkew.java * * * @author *sakoba(java.mesexemples.com) @version 1.00 2013/4/26 */ import java.io.FileOutputStream; import java.io.IOException; import com.itextpdf.text.Chunk; import …
-
Java: Créer une interface graphique basée sur un document XML*
{filelink=8737} /***** Code de MesExemples.com *******/ import java.awt.BorderLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.FileInputStream;import javax.swing.JButton;import javax.swing.JComponent;import javax.swing.JFrame;import javax.swing.JPanel;import org.xml.sax.Attributes;import org.xml.sax.InputSource;import org.xml.sax.helpers.DefaultHandler;import com.sun.org.apache.xerces.internal.parsers.SAXParser;public class SimpleApp3 implements ActionListener { public static void main(String args[]) { JFrame frame = new JFrame(“SimpleApp Demo”); frame.setSize(400, 400); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); new SimpleApp3(frame); } public SimpleApp3(JFrame frame) { frame.getContentPane().setLayout(new BorderLayout()); XMLComponent xmlComponent = new XMLComponent(); frame.getContentPane().add(“Center”, xmlComponent.build(“ui.xml”)); frame.setVisible(true); } public void actionPerformed(ActionEvent ev) { System.out.println(“You clicked ” + ev.getActionCommand()); }}class XMLComponent extends DefaultHandler { private boolean containerActive = false; private JPanel primaryContainer = new JPanel(); private SAXParser parser = new SAXParser(); public XMLComponent() { super(); } public JComponent build(String xmlDocument) { parser.setContentHandler(this); try { parser.parse(new InputSource(new FileInputStream(xmlDocument))); } catch (Exception ex) { System.out.println(ex); } return primaryContainer; } public void startElement(String namespaceURI, String name, String qName, Attributes atts) { if (name.equals(“button”)) primaryContainer.add(new JButton(atts.getValue(“label”))); }}// ui.xml/* * * * */ Code testé avec le fichier XML Suivant Sakoba Adams Rappel Ne m’oubliez pas ce week-end!
-
Java-PDF: Annoter un document avec une vidéo
{filelink=10328} /***** Code de MesExemples.com *******/ import java.io.FileOutputStream; import java.net.URL; import com.itextpdf.text.Annotation; import com.itextpdf.text.Chunk; import com.itextpdf.text.Document; import com.itextpdf.text.Image; import com.itextpdf.text.PageSize; import com.itextpdf.text.Paragraph; import com.itextpdf.text.pdf.PdfAction; import …
-
Javascript: Evaluer une expression avec URL pseudoprotocol
{filelink=2} //Afficher le modulo javascript:md= 5%2; document.write(“” + md); // Comparaison javascript:x = 3; (x > 5)? document.write(“” + “x est plus petit”): document.write(“” + …
-
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 …
-
Javascript: Déterminer la nature d’un objet avec instanceof
{filelink=6} var date = new Date( ); // Créer un objet Date avec un constructeur vide document.write(“”+ (date instanceof Date)); // true; car date est …
-
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 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 …
-
Java: Copier un document XML
{filelink=8372} /***** 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 …
-
Java: Créer un fichier PDF
{filelink=23} import java.io.FileOutputStream; import java.io.IOException; import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; import com.itextpdf.text.Paragraph; import com.itextpdf.text.Rectangle; import com.itextpdf.text.pdf.PdfWriter; public class ExemplePDF { public static void main(String[] args) throws …
-
Java-PDF: Exemple des annotation avec des applications
{filelink=10325} /***** Code de MesExemples.com *******/ import java.io.FileOutputStream; import java.net.URL; import com.itextpdf.text.Annotation; import com.itextpdf.text.Chunk; import com.itextpdf.text.Document; import com.itextpdf.text.Image; import com.itextpdf.text.PageSize; import com.itextpdf.text.Paragraph; import com.itextpdf.text.pdf.PdfAction; import …
-
Javascript: scinder une chaîne en token avec la méthode split
{filelink=38} var inputString = ‘Nom=Fred,Prenom=Alfred,pays=UK,email=”alfred@googlemail.com”‘; // Utiliser la virgule comme séparateur var tabTokens = inputString.split(‘,’,3); for (var i in tabTokens) { // Afficher les tokens …
Cet article Java xerces: Analyser un document XML avec SAX est apparu en premier sur .