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 :

Créer un nouvel élément dans un fichier XML


Sujet :

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

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre à l'essai
    Femme Profil pro
    Administrateur de base de données
    Inscrit en
    Juillet 2013
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Morbihan (Bretagne)

    Informations professionnelles :
    Activité : Administrateur de base de données
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Juillet 2013
    Messages : 5
    Par défaut Créer un nouvel élément dans un fichier XML
    Bonjour à tous je travaille avec JAXB. Je veux insérer dans un document xml un nouveau élément
    Voici le document xml de départ:
    Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    <?xml version="1.0" encoding="utf-8"?>
    <GraphicView>
        <GraphicObjects>
          <Group TransformationPointPosition="Center">
                <GraphicObjects>
                  <Rectangle Matrix="0.2399999;0;0;0.2299999;3.248453E-06;-3.129244E-06" TransformationPointPosition="Center" FillStyle="SymetricGradient" />
                </GraphicObjects>
              </Group>
             <Rectangle Matrix="0.2399999;0;0;0.2299999;3.248453E-06;1.385808E-05" Name="Select" TransformationPointPosition="Center" StrokeColor="#ffffff" StrokeThickness="2" Filled="False" FillStyle="None">
                <AnimationProperties>
                  <Animation.Visibility Name="Digital" Input0="Select" />
                </AnimationProperties>
              </Rectangle>
        </GraphicObjects>
    <GraphicView>

    Voici le document que je souhaiterait obtenir:

    Code XML : 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
    <?xml version="1.0" encoding="utf-8"?>
    <GraphicView>
        <GraphicObjects>
          <Group TransformationPointPosition="Center">
                <GraphicObjects>
                  <Rectangle Matrix="0.2399999;0;0;0.2299999;3.248453E-06;-3.129244E-06" TransformationPointPosition="Center" FillStyle="SymetricGradient" />
                </GraphicObjects>
              </Group>
             <Rectangle Matrix="0.2399999;0;0;0.2299999;3.248453E-06;1.385808E-05" Name="Select" TransformationPointPosition="Center" StrokeColor="#ffffff" StrokeThickness="2" Filled="False" FillStyle="None">
                <AnimationProperties>
                  <Animation.Visibility Name="Digital" Input0="Select" />
                </AnimationProperties>
              </Rectangle>
             <View ReferenceViewName="../Voyant2" X="9" Y="8" Width="8" Height="8" TransformationPointPosition="Center" Filled="False" />
        </GraphicObjects>
    <GraphicView>

    En fait mon objectif c'est d'insérer la balise View dans à la fin de la balise GraphicObjects.

    - J'ai mis la balise View dans un autre fichier xml afin de fusionner les 2 fichiers mais je n'obtient pas le résultat. J'arrive à charger les deux fichier. Comment mettre le contenu de l'un dans l'autre.

    Quelqu'un aurait-il une idée?

  2. #2
    Modérateur

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

    Informations forums :
    Inscription : Septembre 2004
    Messages : 12 582
    Par défaut
    - Charger les deux fichiers dans un objet GraphicView et un objet View.
    - L'objet GraphicView contient un objet GraphicObjects, qui contient un objet View qui vaut null. Remplacer ce null par l'objet View chargé avce le deuxième fichier.
    - Écrire l'objet GraphicView ainsi mis à jour, dans un nouveau fichier XML.
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  3. #3
    Membre à l'essai
    Femme Profil pro
    Administrateur de base de données
    Inscrit en
    Juillet 2013
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Morbihan (Bretagne)

    Informations professionnelles :
    Activité : Administrateur de base de données
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Juillet 2013
    Messages : 5
    Par défaut fichier xml plus lisibles
    Fichier1.xml
    Code XML : 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
     
    <?xml version="1.0" encoding="utf-8"?>
    <GraphicView>
         <GraphicObjects>
         <Group TransformationPointPosition="Center">
           <GraphicObjects>
              <Rectangle Matrix="0.2399999;0;0;0.2299999;3.248453E-    06;-3.129244E-06" TransformationPointPosition="Center"   FillStyle="SymetricGradient" />
            </GraphicObjects>
         </Group>
        <Rectangle Matrix="0.2399999;0;0;0.2299999;3.248453E-06;1.385808E-05" Name="Select" TransformationPointPosition="Center" StrokeColor="#ffffff" StrokeThickness="2" Filled="False" FillStyle="None">
            <AnimationProperties>
            <Animation.Visibility Name="Digital" Input0="Select" />
            </AnimationProperties>
         </Rectangle>
      </GraphicObjects>
    <GraphicView>

    Fichier à obtenir

    Code XML : 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
     
    <?xml version="1.0" encoding="utf-8"?>
    <GraphicView>
    <GraphicObjects>
    <Group TransformationPointPosition="Center">
    <GraphicObjects>
    <Rectangle Matrix="0.2399999;0;0;0.2299999;3.248453E-06;-3.129244E-06" TransformationPointPosition="Center" FillStyle="SymetricGradient" />
    </GraphicObjects>
    </Group>
    <Rectangle Matrix="0.2399999;0;0;0.2299999;3.248453E-06;1.385808E-05" Name="Select" TransformationPointPosition="Center" StrokeColor="#ffffff" StrokeThickness="2" Filled="False" FillStyle="None">
    <AnimationProperties>
    <Animation.Visibility Name="Digital" Input0="Select" />
    </AnimationProperties>
    </Rectangle>
    <View ReferenceViewName="../Voyant2" X="9" Y="8" Width="8" Height="8" TransformationPointPosition="Center" Filled="False" />
    </GraphicObjects>
    <GraphicView>

  4. #4
    Membre à l'essai
    Femme Profil pro
    Administrateur de base de données
    Inscrit en
    Juillet 2013
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Morbihan (Bretagne)

    Informations professionnelles :
    Activité : Administrateur de base de données
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Juillet 2013
    Messages : 5
    Par défaut
    Merci pour la réponse. J'ai essayé de suivre vos indication mais je ne sais pas comment spécifier que l'objet GraphicView possède un objet View nul. Voici là où j'en suis:
    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
     
    package CA;
     
    import java.io.File;
    import javax.xml.bind.JAXBContext;
    import javax.xml.bind.JAXBException;
    import javax.xml.bind.Marshaller;
    import javax.xml.bind.Unmarshaller;
    import CA.GraphicView.View;
    import CA.GraphicView.View.GraphicObjects;
     
    public class AdaptationCA {
     
    	private static Marshaller mapperObjetsXML;
    	private static Unmarshaller mapperXMLObjets;
    	private static File file1 = new File("D:\\CA.cfg"); 
    	private static File file2 = new File("D:\\TR1.cfg"); 
    	private static File file3 = new File("D:\\View.cfg"); 
    	static ObjectFactory fabrique = new ObjectFactory();
    	static JAXBContext context;
    	static GraphicView graphV1;
    	static View embed;
    public static void Mapper(){
    				try {
    					context = JAXBContext.newInstance("CA");
     
    					// création d'un marshaller. L'objet créé va permettre de transformer un ensemble d'objet en un document xml
    					mapperObjetsXML = context.createMarshaller();
    					mapperObjetsXML.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
     
    					// création d'un unmarshaller. l'objet créé va permettre de transformer le document XML en un ensemble d'objet
    					mapperXMLObjets = context.createUnmarshaller() ;
     
    					graphV1 = (GraphicView)mapperXMLObjets.unmarshal(file1);
    					embed = (EmbeddedView)mapperXMLObjets.unmarshal(file3);
     
     
    				} catch (JAXBException e) {
     
    					e.printStackTrace();
    				}
     
    			}
     
    /***************************************************************************************************/
    /**********************INCRUSTER LA VUE DE L'ANIMATION DU DEFAUT DE MATERIEL OU DE COMMANDE*********/
    /***************************************************************************************************/
     
     
    private static void AddEmbeddedView(String refVName, int x, int y, int width, int height, String transf, String fil){
    				View v = graphV1.getView();
    				GraphicObjects graphO = v.getGraphicObjects();
     
    				//EmbeddedView emb = new EmbeddedView();
     
     
     
    			}
     
     
     
     
         private static void enregistrer() {
    		try {
    							        mapperObjetsXML.marshal(graphV1, file2);
     
    		}
    		catch (JAXBException ex) { 
    		ex.printStackTrace();
     
    		}
    	}
     
     
     
     
     
     
    public static void main(String[] args) throws Exception {
     
    	Mapper();
    	AddEmbeddedView("../Voyant2", 63, 19, 24, 23, "Center", "False");
    	enregistrer();
     
    		}
     
    }

  5. #5
    Membre à l'essai
    Femme Profil pro
    Administrateur de base de données
    Inscrit en
    Juillet 2013
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Morbihan (Bretagne)

    Informations professionnelles :
    Activité : Administrateur de base de données
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Juillet 2013
    Messages : 5
    Par défaut
    Excusez moi pour cette erreur : là où il y a EmbeddedView c'est View.

  6. #6
    Membre à l'essai
    Femme Profil pro
    Administrateur de base de données
    Inscrit en
    Juillet 2013
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Morbihan (Bretagne)

    Informations professionnelles :
    Activité : Administrateur de base de données
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Juillet 2013
    Messages : 5
    Par défaut
    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
     
    package CA;
     
    import java.io.File;
    import javax.xml.bind.JAXBContext;
    import javax.xml.bind.JAXBException;
    import javax.xml.bind.Marshaller;
    import javax.xml.bind.Unmarshaller;
    import CA.GraphicView.View;
    import CA.GraphicView.View.GraphicObjects;
     
    public class AdaptationCA {
     
    	private static Marshaller mapperObjetsXML;
    	private static Unmarshaller mapperXMLObjets;
    	private static File file1 = new File("D:\\CA.cfg"); 
    	private static File file2 = new File("D:\\TR1.cfg"); 
    	private static File file3 = new File("D:\\View.cfg"); 
    	static ObjectFactory fabrique = new ObjectFactory();
    	static JAXBContext context;
    	static GraphicView graphV1;
    	static View embed;
    public static void Mapper(){
    				try {
    					context = JAXBContext.newInstance("CA");
     
    					// création d'un marshaller. L'objet créé va permettre de transformer un ensemble d'objet en un document xml
    					mapperObjetsXML = context.createMarshaller();
    					mapperObjetsXML.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
     
    					// création d'un unmarshaller. l'objet créé va permettre de transformer le document XML en un ensemble d'objet
    					mapperXMLObjets = context.createUnmarshaller() ;
     
    graphV1 = (GraphicView)mapperXMLObjets.unmarshal(file1);
    embed = (View)mapperXMLObjets.unmarshal(file3);
     
     
    				} catch (JAXBException e) {
     
    					e.printStackTrace();
    				}
     
    			}
     
    /***************************************************************************************************/
    /**********************INCRUSTER LA VUE DE L'ANIMATION DU DEFAUT DE MATERIEL OU DE COMMANDE*********/
    /***************************************************************************************************/
     
     
    private static void AddEmbeddedView(String refVName, int x, int y, int width, int height, String transf, String fil){
     
    	GraphicObjects graphO = graphV1.getGraphicObjects();
     
    				embed.getFilled();
    				embed.getHeight();
    				embed.getReferenceViewName();
    				embed.getTransformationPointPosition();
    				embed.getWidth();
    				embed.getX();
    				embed.getY();
     
     
     
     
    			}
     
     
     
     
         private static void enregistrer() {
    		try {
    							        mapperObjetsXML.marshal(graphV1, file2);
     
    		}
    		catch (JAXBException ex) { 
    		ex.printStackTrace();
     
    		}
    	}
     
     
     
     
     
     
    public static void main(String[] args) throws Exception {
     
    	Mapper();
    	AddView("../Voyant2", 63, 19, 24, 23, "Center", "False");
    	enregistrer();
     
    		}
     
    }
    J'ai une erreur qui s'affiche lors de la compilation

Discussions similaires

  1. Chercher 2 éléments dans un fichier XML de 80mo
    Par Immobilis dans le forum ASP.NET
    Réponses: 8
    Dernier message: 02/06/2008, 23h09
  2. [DOM] Insertion d'élément dans un fichier XML en PHP
    Par marcus13 dans le forum Bibliothèques et frameworks
    Réponses: 4
    Dernier message: 03/04/2008, 13h51
  3. [XPATH] Récupérer un élément dans un fichier XML
    Par be_tnt dans le forum XSL/XSLT/XPATH
    Réponses: 7
    Dernier message: 07/06/2007, 19h49
  4. Comment ajouter un élément dans un fichier XML
    Par sorilazer dans le forum Format d'échange (XML, JSON...)
    Réponses: 5
    Dernier message: 04/06/2007, 21h56
  5. Réponses: 14
    Dernier message: 01/12/2003, 17h47

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