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

Persistance des données Java Discussion :

Mapping Java <-> XML (Castor)


Sujet :

Persistance des données Java

  1. #1
    Candidat au Club
    Inscrit en
    Août 2006
    Messages
    6
    Détails du profil
    Informations forums :
    Inscription : Août 2006
    Messages : 6
    Points : 3
    Points
    3
    Par défaut Mapping Java <-> XML (Castor)
    Bonjour,

    Je débute avec Castor, et je suis confronté au problème suivant...

    Je souhaiterais parser la classe suivante :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    public class TakingAway {
     
    	private String apheresisOfPlates;
    	private String apheresisOfPlatesMachineType;
    	private String otherApheresisOfPlatesMachineType;
    	private String apheresisOfPlatesAutolog;
     
    	private String plasmapheresis;
    	private String plasmapheresisMachineType;
    	private String otherPlasmapheresisMachineType;
    	private String plasmapheresisAutolog;	
                ...

    Je souhaiterais obtenir l'xml suivant :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
        <taking-away>
           <apheresis-of-plates value="on" autolog="on">
              <machine-type other="test">Other</machine-type>
           </apheresis-of-plates>
           <plasmapheresis value="on" autolog="on">
              <machine-type other="test2">Other</machine-type>
           </plasmapheresis>
           ...

    En utilisant le mapping castor :
    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
     
    <n:mapping xmlns:n="http://castor.exolab.org/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://castor.exolab.org/ C:\JavaDev\workspaces\healthcare\castor\castortest\mapping.xsd">
      <n:class name="be.medical.blood.beans.TakingAway">
     
        <n:field name="apheresisOfPlates" type="java.lang.String">
          <n:bind-xml name="value" node="attribute" location="apheresis-of-plates"/>
        </n:field>
        <n:field name="apheresisOfPlatesAutolog" type="java.lang.String">
          <n:bind-xml name="autolog" node="attribute" location="apheresis-of-plates"/>
        </n:field>
        <n:field name="apheresisOfPlatesMachineType" type="java.lang.String">
          <n:bind-xml name="machine-type" node="element" location="apheresis-of-plates"/>
        </n:field>
          <n:field name="otherApheresisOfPlatesMachineType" type="java.lang.String">
            <n:bind-xml name="other" node="attribute" location="machine-type"/>
          </n:field>
     
        <n:field name="plasmapheresis" type="java.lang.String">
          <n:bind-xml name="value" node="attribute" location="plasmapheresis"/>
        </n:field>
        <n:field name="plasmapheresisAutolog" type="java.lang.String">
          <n:bind-xml name="autolog" node="attribute" location="plasmapheresis"/>
        </n:field>
        <n:field name="plasmapheresisMachineType" type="java.lang.String">
          <n:bind-xml name="machine-type" node="element" location="plasmapheresis"/>
        </n:field>
        <n:field name="otherPlasmapheresisMachineType" type="java.lang.String">
          <n:bind-xml name="other" node="attribute" location="machine-type"/>
        </n:field>
        ....

    j'obitens l'xml suivant :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
        <taking-away>
            <apheresis-of-plates value="on" autolog="on">
                <machine-type other="test" other="test2">Other</machine-type>
            </apheresis-of-plates>
            <plasmapheresis>
                <machine-type>Other</machine-type>
            </plasmapheresis>
            ...

    Comment faire pour que le second other soit lié au plasmapheresis ?

    D'avance merci pour votre aide...

  2. #2
    Membre régulier

    Profil pro
    Laveur
    Inscrit en
    Avril 2004
    Messages
    142
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Laveur

    Informations forums :
    Inscription : Avril 2004
    Messages : 142
    Points : 81
    Points
    81
    Par défaut
    Salut

    moi je supposerai que comme tu appelles

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    <n:field name="otherApheresisOfPlatesMachineType" type="java.lang.String">
    
    <n:bind-xml name="other" node="attribute" location="machine-type"/>
    et

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    <n:field name="otherPlasmapheresisMachineType" type="java.lang.String">
    <n:bind-xml name="other" node="attribute" location="machine-type"/>
    de la meme maniere, Castor te fous tout dans le meme noeud

    Essaie de donner une nom différent

    essai :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    <n:field name="otherPlasmapheresisMachineType" type="java.lang.String">
    <n:bind-xml name="otherPlasma" node="attribute" location="machine-type"/>
    pour le second appel

  3. #3
    Candidat au Club
    Inscrit en
    Août 2006
    Messages
    6
    Détails du profil
    Informations forums :
    Inscription : Août 2006
    Messages : 6
    Points : 3
    Points
    3
    Par défaut
    Merci pour ta proposition, mais cela n'arrange pas mon problème.

    En applicant ta modification, je me retrouve avec :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
        <taking-away>
            <apheresis-of-plates value="on" autolog="on">
                <machine-type other="A" otherPlasma="E">Other</machine-type>
            </apheresis-of-plates>
            <plasmapheresis>
                <machine-type>Other</machine-type>
            </plasmapheresis>
        ...
    Je pense qu'il faut chercher une solution au niveau du "location", mais je ne parviens pas à trouver cette solution...

  4. #4
    Futur Membre du Club
    Profil pro
    Inscrit en
    Septembre 2006
    Messages
    7
    Détails du profil
    Informations personnelles :
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations forums :
    Inscription : Septembre 2006
    Messages : 7
    Points : 8
    Points
    8
    Par défaut
    Essai ceci:

    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
    <n:mapping xmlns:n="http://castor.exolab.org/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://castor.exolab.org/ C:\JavaDev\workspaces\healthcare\castor\castortest\mapping.xsd">
      <n:class name="be.medical.blood.beans.TakingAway">
    
        <n:field name="apheresisOfPlates" type="java.lang.String">
          <n:bind-xml name="value" node="attribute" location="apheresis-of-plates"/>
        </n:field>
        <n:field name="apheresisOfPlatesAutolog" type="java.lang.String">
          <n:bind-xml name="autolog" node="attribute" location="apheresis-of-plates"/>
        </n:field>
        <n:field name="apheresisOfPlatesMachineType" type="java.lang.String">
          <n:bind-xml name="machine-type" node="element" location="apheresis-of-plates"/>
        </n:field>
          <n:field name="otherApheresisOfPlatesMachineType" type="java.lang.String">
            <n:bind-xml name="other" node="attribute" location="apheresis-of-plates/machine-type"/>
          </n:field>
    
        <n:field name="plasmapheresis" type="java.lang.String">
          <n:bind-xml name="value" node="attribute" location="plasmapheresis"/>
        </n:field>
        <n:field name="plasmapheresisAutolog" type="java.lang.String">
          <n:bind-xml name="autolog" node="attribute" location="plasmapheresis"/>
        </n:field>
        <n:field name="plasmapheresisMachineType" type="java.lang.String">
          <n:bind-xml name="machine-type" node="element" location="plasmapheresis"/>
        </n:field>
        <n:field name="otherPlasmapheresisMachineType" type="java.lang.String">
          <n:bind-xml name="other" node="attribute" location="plasmapheresis/machine-type"/>
        </n:field>
        ....

Discussions similaires

  1. Erreur OpenFileMapping Mapping JAVA-XML
    Par specsy dans le forum Format d'échange (XML, JSON...)
    Réponses: 0
    Dernier message: 01/02/2009, 10h35
  2. Mapping Java - XML
    Par hlr dans le forum Persistance des données
    Réponses: 6
    Dernier message: 14/10/2005, 11h59
  3. [XSD][JAVA] Valider un XML avec un XSD schéma
    Par vad dans le forum Valider
    Réponses: 1
    Dernier message: 17/08/2005, 11h47
  4. [SAX] Passer d'objet java en fichier XML?
    Par spoutyoyo dans le forum Format d'échange (XML, JSON...)
    Réponses: 15
    Dernier message: 05/01/2005, 08h31
  5. recherche dans un fichier xml (castor)
    Par pingoui dans le forum Format d'échange (XML, JSON...)
    Réponses: 8
    Dernier message: 06/09/2004, 14h28

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