IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Format d'échange (XML, JSON...) Java Discussion :

Enlever le "standalone= yes"


Sujet :

Format d'échange (XML, JSON...) Java

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    144
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 144
    Points : 54
    Points
    54
    Par défaut Enlever le "standalone= yes"
    Bonjour,

    Dans un programme JAVA, je restitue un fichier XML en sortie.

    Dans la première balise, voici ce qu'il m'indique :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    Comment faire pour enlever ce " standalone="yes" " ?

    Merci.

    Pascal.

  2. #2
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    Tu restitue le fichier avec quoi?

  3. #3
    Membre émérite
    Avatar de polymorphisme
    Homme Profil pro
    Publishing
    Inscrit en
    Octobre 2009
    Messages
    1 460
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Publishing
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2009
    Messages : 1 460
    Points : 2 371
    Points
    2 371
    Par défaut
    Oui, tu utilise quelle API ? SAX, DOM, JAXP, ...
    ou peut-être une application Xerces, Xalan, Saxon, ... ?
    Article : Installation de Cocoon
    Je ne réponds pas aux MP à caractère technique.

  4. #4
    Modérateur

    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    12 553
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2004
    Messages : 12 553
    Points : 21 609
    Points
    21 609
    Par défaut
    S'il nous dit qu'il utilise DOM on sera bien avancés -_-°.

    On a besoin du bout de code qui fait la génération.
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  5. #5
    Membre du Club
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    144
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 144
    Points : 54
    Points
    54
    Par défaut
    Bonjour,

    J'utilise JAXP.

    Merci.

  6. #6
    Modérateur

    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    12 553
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2004
    Messages : 12 553
    Points : 21 609
    Points
    21 609
    Par défaut
    Je vous jure que je ne sais pas lire l'avenir.

    Bref, comme dit dans le message juste avant :

    Citation Envoyé par Moi, une heure avant
    On a besoin du bout de code qui fait la génération.
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  7. #7
    Membre du Club
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    144
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 144
    Points : 54
    Points
    54
    Par défaut
    Le code

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    package com.inet.dd5.service1;
     
    import java.io.BufferedWriter;
    import java.io.FileNotFoundException;
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.OutputStreamWriter;
    import java.io.UnsupportedEncodingException;
    import java.io.Writer;
     
    import javax.xml.bind.JAXBContext;
    import javax.xml.bind.JAXBException;
    import javax.xml.bind.MarshalException;
    import javax.xml.bind.Marshaller;
    import javax.xml.bind.ValidationException;
    import javax.xml.validation.Schema;
    import javax.xml.validation.SchemaFactory;
     
    import org.apache.log4j.Logger;
    import org.xml.sax.SAXException;
     
    import com.inet.dd5.erreur.ErreurFichierTraitement;
    import de.kba.verwendungsnachweis.ContainerTyp;
     
     
     
    /**
     * Classe regroupant les methodes d'ecriture du fichier XML
     *      
     */
    public class EcritureFichierXML 
    {
    	private Writer out;
    	private Marshaller marshaller;
    	public static final String FILE_ENCODING = "UTF-8"; // "ISO-8859-1" ou "ISO-8859-15" ou "UTF-16"
    	private static Logger log = Logger.getLogger(EcritureFichierXML.class);
     
    	/**
             * 
             * Constructeur initialisant l'objet Marshall
             * @param nomFichierSortie Le chemin complet du fichier de sortie 
             * @throws IOException
             */
    	public EcritureFichierXML(String nomFichierSortie) throws IOException 
    	{	
    		out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(nomFichierSortie), FILE_ENCODING));  
     
    		try {
     
    			JAXBContext jc = JAXBContext.newInstance( "de.kba.verwendungsnachweis" );
     
    			Schema schema = null ;
     
     
     
     
    			try {
    				// creation de l'instance chemin
    				File schemaFile = new File("Ressources/vwn_extern_V_1_0.xsd");
    				// creation de l'instance schema xsd
    	    	schema = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(schemaFile);
    			} catch (SAXException e) {
    				log.error("Impossible de lire le schéma XML (fichiers XSD)", e);
    			}
     
     
     
    			marshaller = jc.createMarshaller();
    			marshaller.setSchema(schema);
    			// Permet de tabuler
    			marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.valueOf(true));
     
    		} catch (JAXBException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    			log.error("Impossible de lire le schéma XML (fichiers XSD)", e);
    		}
    	}
     
    	/**
             * Ecriture d'un enregistrement RECORD du fichier XML de sortie
             * @param record Enregistrement du fichier
             * @throws ErreurFichierTraitement
             * @throws JAXBException 
             * @throws FileNotFoundException 
             * @throws UnsupportedEncodingException 
             */
    	public void writeServiceDMR(ContainerTyp newContainerTyp  ) throws ErreurFichierTraitement, JAXBException, UnsupportedEncodingException, FileNotFoundException 
    	{
    		try 
    		{
    			marshaller.marshal(newContainerTyp, out);				
    		} 
    		catch (MarshalException e1) 
    		{
    			log.fatal("Marshall impossible : (constitution du fichier XML)");
    			e1.printStackTrace();
    			throw new ErreurFichierTraitement("Marshall impossible : (constitution du fichier XML)");
    		} 
    		catch (ValidationException e1) 
    		{
    			log.fatal("Le fichier a un format non valide");
    			e1.printStackTrace();
    			throw new ErreurFichierTraitement("Le fichier a un format non valide)");
    		}
    	}
    }
    Merci.

    Pascal.

  8. #8
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    marshaller.setProperty("com.sun.xml.bind.xmlDeclaration", Boolean.FALSE);
    Mais la question est plutot, pourquoi avoir besoin de virer une information qui est standard dans le xml.

  9. #9
    Membre émérite
    Avatar de polymorphisme
    Homme Profil pro
    Publishing
    Inscrit en
    Octobre 2009
    Messages
    1 460
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Publishing
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2009
    Messages : 1 460
    Points : 2 371
    Points
    2 371
    Par défaut
    Pour obtenir l'instruction de traitement <?xml version="1.0" encoding="UTF-8"?>,
    tu peut utiliser :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    final ByteArrayOutputStream buff = new ByteArrayOutputStream();
    final PrintWriter writer = new PrintWriter(buff);
    final Marshaller marshaller = jaxbContext.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
    writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    marshaller.marshal(response, writer);

    Remarque : thelvin, j'ai pensé à DOM car il m'est venu en tête le code suivant :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    DOMImplementationLS lsImpl = (DOMImplementationLS)node.getOwnerDocument().getImplementation().getFeature("LS", "3.0");
    LSSerializer lsSerializer = lsImpl.createLSSerializer();
    lsSerializer.getDomConfig().setParameter("xml-declaration", false);
    scalpa63 : pourras tu nous laissez le code que tu as finit par choisir ?
    Article : Installation de Cocoon
    Je ne réponds pas aux MP à caractère technique.

  10. #10
    Membre du Club
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    144
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 144
    Points : 54
    Points
    54
    Par défaut
    Bonjour,

    Ok, je vous tiendrais au courant.

    Merci.

    Pascal.

  11. #11
    Modérateur

    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    12 553
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2004
    Messages : 12 553
    Points : 21 609
    Points
    21 609
    Par défaut
    Citation Envoyé par polymorphisme Voir le message
    Remarque : thelvin, j'ai pensé à DOM car il m'est venu en tête le code suivant :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    DOMImplementationLS lsImpl = (DOMImplementationLS)node.getOwnerDocument().getImplementation().getFeature("LS", "3.0");
    LSSerializer lsSerializer = lsImpl.createLSSerializer();
    lsSerializer.getDomConfig().setParameter("xml-declaration", false);

    Et ce code pourrait très bien n'avoir rien à voir avec la manière dont la personne utilise DOM.
    Là n'est pas la question. Si la personne dit qu'elle utilise DOM on est pas plus avancé. Si elle qu'elle utilise SAX on n'est pas plus avancé. Si elle dit qu'elle utilise JAXB on peut à la rigueur supposer des trucs mais avec de fortes chances de se planter. Si elle dit qu'elle utilise JAXP... Alors là c'est pas franchement différent d'avoir rien dit.
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

Discussions similaires

  1. Quote et double quote
    Par aktos dans le forum Langage
    Réponses: 8
    Dernier message: 05/01/2007, 19h55

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo