/***** Code de MesExemples.com *******/ import java.io.File;import java.io.FileInputStream;import javax.xml.stream.XMLInputFactory;import javax.xml.stream.XMLStreamReader;public class MainClass { public static void main(String[] args) throws Exception { File file = new File("test.xml"); XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLStreamReader reader = inputFactory.createXMLStreamReader(new FileInputStream(file)); while (reader.getEventType() == 6) reader.next(); int eventTypeID = reader.next(); System.out.println("Hello " + reader.getText()); }} |
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
-
Javascript: Trouver un caractère dans une chaîne avec charAt()
{filelink=35} var text = new String(“Apprendre javascript”); var sTxt = text.charAt(3); document.writeln(sTxt); // retourne ‘r’
-
Java XML: Trouver le containeur avec attribut ou le créer
{filelink=8365} /***** Code de MesExemples.com *******/ import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.ArrayList;import java.util.Date;import java.util.Iterator;import org.w3c.dom.Document;import org.w3c.dom.Element;import org.w3c.dom.Node;import org.w3c.dom.NodeList;/******************************************************************************* * Copyright (C) 2007 Google Inc. * * Licensed 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. ******************************************************************************//** * Various XML utilities. * * @author simonjsmith, ksim * @version 1.1 – ksim – March 6th, 2007 – Added functions regarding streaming * @version 1.2 – ksim – March 10th, 2007 – Added functions regarding DOM * manipulation */public class Utils { public static Element findContainerWithAttributeValueElseCreate( Document document, Element parent, String element, String attributeName, String attributeValue) { NodeList nl = parent.getElementsByTagName(element); Element e; for (int i = 0; i
-
Java XML: Trouver le containeur avec attribut ou le créer
{filelink=8365} /***** Code de MesExemples.com *******/ import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.ArrayList;import java.util.Date;import java.util.Iterator;import org.w3c.dom.Document;import org.w3c.dom.Element;import org.w3c.dom.Node;import org.w3c.dom.NodeList;/******************************************************************************* * Copyright (C) 2007 Google Inc. * * Licensed 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. ******************************************************************************//** * Various XML utilities. * * @author simonjsmith, ksim * @version 1.1 – ksim – March 6th, 2007 – Added functions regarding streaming * @version 1.2 – ksim – March 10th, 2007 – Added functions regarding DOM * manipulation */public class Utils { public static Element findContainerWithAttributeValueElseCreate( Document document, Element parent, String element, String attributeName, String attributeValue) { NodeList nl = parent.getElementsByTagName(element); Element e; for (int i = 0; i
-
Java XML: Trouver un élément et afficher son texte*
{filelink=8397} /***** Code de MesExemples.com *******/ /** * @(#)AfficherTextElement.java * * * @author *sakoba(java.mesexemples.com) @version 1.00 2013/7/4 */ import java.io.File; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import …
-
Java XML: Exemple d’utilisation de Constant ‘XMLStreamConstants.START_ELEMENT’
{filelink=8749} /***** Code de MesExemples.com *******/ /** * @(#)ExempleXMLStreamConstants.java * * * @author *sakoba(java.mesexemples.com) @version 1.00 2013/7/5 */ import java.io.File; import java.io.FileInputStream; import javax.xml.stream.XMLInputFactory; import …
-
Java XML: Une méthode récursive pour trouver la valeur d’un attribut Spécifique
{filelink=8368} /***** Code de MesExemples.com *******/ /** * @(#)ExempleValeurAttribut.java * * * @author *sakoba(java.mesexemples.com) @version 1.00 2013/7/4 */ import javax.xml.namespace.QName; import org.w3c.dom.Document; import org.w3c.dom.Element; import …
-
Exemple de STAX cursor
{filelink=985} import java.io.FileInputStream; import javax.xml.namespace.QName; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import javax.xml.stream.events.XMLEvent; class StaxCursorTest { public static void main(String[] args) throws Exception { String …
-
Exemple de Gestion d’exception XMLStreamException « »
{filelink=986} import java.io.FileInputStream; import javax.xml.namespace.QName; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import javax.xml.stream.events.XMLEvent; class StaxCursorTest { public static void main(String[] args) throws Exception { String …
-
Comment Obtenir les Informations comme un objet XMLEvent »”
{filelink=987} import java.io.FileInputStream; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamConstants; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import javax.xml.stream.events.StartElement; import javax.xml.stream.events.XMLEvent; import javax.xml.stream.util.XMLEventAllocator; import com.sun.xml.internal.stream.events.XMLEventAllocatorImpl; class CursorApproachEventObject { static XMLEventAllocator allocator …
-
Stax XML: Déplacer le curseur à travers les noeud
{filelink=976} import java.io.FileReader; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamReader; import javax.xml.stream.events.XMLEvent; public class XMLDeplaceCurseur { public static void main(String args[]) throws Exception { XMLInputFactory xmliFactory = XMLInputFactory.newInstance(); …
-
Javascript: Trouver la plus grand valeur d’un tableau
{filelink=570} var data = [1,2,3,4,5,6,7,-8]; var max=Math.max.apply(null, data); document.write(“La valeur Maximale du tableau est: “+max);
-
STAX et XML: Afficher les informations des éléments(noms, valeurs et attributs)
{filelink=977} import java.io.FileReader; import java.io.Reader; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamConstants; import javax.xml.stream.XMLStreamReader; public class XMLTraitementElems { private static void TraiterNoeuds(XMLStreamReader reader) { int typeEven = reader.getEventType(); …
-
XML: Utilisation de ‘StreamFilter’ pour analyser le document
{filelink=982} import java.io.*; import java.nio.MappedByteBuffer; import java.nio.channels.FileChannel; import javax.xml.stream.*; import javax.xml.stream.events.*; import java.util.Date; import javax.xml.namespace.QName; public class AnalyseXML implements javax.xml.stream.StreamFilter { public static final String …
-
Javascript-DOM: trouver un élément par son nom
{filelink=75} function findElemName() { // Obtenir tous les éléments nommés ‘elem’ for (var i = 1; i <= 7; i++) { var elemName = "elem" …
-
Javascript: Extraire les arguments d’un URL
{filelink=48} function getArgs( ) { var args = new Object( ); // Obtenir la chaîne de requête var requete = location.search.substring(1); // Stocker la liste …
Cet article Java: Trouver l’élément suivant avec XMLStreamReader est apparu en premier sur .