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 :

Stax et indentation


Sujet :

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

  1. #1
    Membre éprouvé
    Homme Profil pro
    Technophile Web
    Inscrit en
    Mai 2007
    Messages
    930
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations professionnelles :
    Activité : Technophile Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2007
    Messages : 930
    Par défaut Stax et indentation
    Bonjour,

    y a t'il moyen avec STAX d'indenter un ficher XML. Le mein ressemble à ça et c'est pas très joli
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <?xml version="1.0" encoding="UTF-8"?><?xml version="1.0" ?><enquiry xmlns:dtl="http://datalion.eu"></enquiry>
    voic le bout de code qui me sert à créer ce fichier
    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
    public void write()
    	{
    		XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
    		try
    		{
    			this.output = new FileOutputStream(URL);
    			this.writer = outputFactory.createXMLStreamWriter(output);
    			this.writer.writeStartDocument(this.ENCODING, this.VERSION);
    			this.writer.writeStartDocument();
    			this.writer.setPrefix("tns",this.NS);
    			this.writer.setDefaultNamespace(this.NS);
    			this.writer.writeStartElement(this.NS,"enquiry");
    			this.writer.writeNamespace("dtl",this.NS);
    			this.writer.writeEndElement();
    		}
    		catch(XMLStreamException e1)
    		{
    			System.out.println("XMLStreamException");
    			e1.printStackTrace();
    		}
    		catch(IOException e2)
    		{
    			System.out.println("File not found");
    			e2.printStackTrace();
    		}
    	}

  2. #2
    Membre chevronné


    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    7 855
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2003
    Messages : 7 855

  3. #3
    Membre éprouvé
    Homme Profil pro
    Technophile Web
    Inscrit en
    Mai 2007
    Messages
    930
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations professionnelles :
    Activité : Technophile Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2007
    Messages : 930
    Par défaut
    dans ce cas j'ai une exception, de type XMLStreamExeption
    je ne sais pas pourquoi le flux XML se forme bien
    voici la trace de l'erreur
    javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1]
    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
    Message: Premature end of file.
    	at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:584)
    	at com.sun.xml.internal.stream.XMLEventReaderImpl.nextEvent(XMLEventReaderImpl.java:83)
    	at com.datalion.exogema.application.Enquiry.write(Enquiry.java:81)
    	at com.datalion.exogema.gui.MenuBarActionListener.actionPerformed(MenuBarActionListener.java:58)
    	at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2013)
    	at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2336)
    	at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)
    	at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:260)
    	at javax.swing.AbstractButton.doClick(AbstractButton.java:375)
    	at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1689)
    	at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1733)
    	at java.awt.Component.processMouseEvent(Component.java:6100)
    	at javax.swing.JComponent.processMouseEvent(JComponent.java:3288)
    	at java.awt.Component.processEvent(Component.java:5865)
    	at java.awt.Container.processEvent(Container.java:2110)
    	at java.awt.Component.dispatchEventImpl(Component.java:4461)
    	at java.awt.Container.dispatchEventImpl(Container.java:2168)
    	at java.awt.Component.dispatchEvent(Component.java:4287)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4466)
    	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4130)
    	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4060)
    	at java.awt.Container.dispatchEventImpl(Container.java:2154)
    	at java.awt.Window.dispatchEventImpl(Window.java:2555)
    	at java.awt.Component.dispatchEvent(Component.java:4287)
    	at java.awt.EventQueue.dispatchEvent(EventQueue.java:605)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:276)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:201)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:191)
    	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:186)
    	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:178)
    	at java.awt.EventDispatchThread.run(EventDispatchThread.java:139)

Discussions similaires

  1. [StAX] indentation avec stax
    Par khaled69100 dans le forum Format d'échange (XML, JSON...)
    Réponses: 2
    Dernier message: 31/10/2008, 15h13
  2. [mise en page] pour bien indenter son code
    Par bihorece dans le forum C++Builder
    Réponses: 4
    Dernier message: 06/08/2003, 16h14
  3. indentation automatique
    Par Boosters dans le forum JBuilder
    Réponses: 3
    Dernier message: 17/07/2003, 16h44
  4. [Source>Format :)] indentation automatik
    Par iubito dans le forum Eclipse Java
    Réponses: 2
    Dernier message: 10/06/2003, 16h37
  5. [indentation]Jbuilder 8
    Par partyboy dans le forum JBuilder
    Réponses: 2
    Dernier message: 26/03/2003, 13h39

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