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 :

[Castor] XML - Ignorer un noeud dans le mapping


Sujet :

Persistance des données Java

  1. #1
    Nouveau Candidat au Club
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    1
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2007
    Messages : 1
    Points : 1
    Points
    1
    Par défaut [Castor] XML - Ignorer un noeud dans le mapping
    Bonjour,

    Je suis en train de faire un mapping Castor et ça ne marche pas comme je voudrais.

    Voici le type de fichier XML qui me pose problème:

    Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    <?xml version="1.0" encoding="UTF-8"?>
    <personne id="id1" nom="nom1" prenom="prenom1" version="1">
       <adresses>
    	<adresse id="id1" rue="rue1" version="1" ville="ville1" />
    	<adresse id="id2" rue="rue2" version="1" ville="ville2" />
       </adresses>
    </personne>


    et voici le fichier de mapping

    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
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    <mapping>
    	<class name="test.bean.Personne">
    		<map-to xml="personne" />
    		<field name="id" type="string">
    			<bind-xml name="id" node="attribute" />
    		</field>
    		<field name="version" type="integer">
    			<bind-xml name="version" node="attribute" />
    		</field>
    		<field name="prenom" type="string">
    			<bind-xml name="prenom" node="attribute" />
    		</field>
    		<field name="nom" type="string">
    			<bind-xml name="nom" node="attribute" />
    		</field>
    		<field name="adresses" collection="arraylist" type="test.bean.Adresse">
    			<bind-xml name="adresse" node="element" />
    		</field>
    	</class>
    	<class name="test.bean.Adresse">
    		<field name="id" type="string">
    			<bind-xml name="id" node="attribute" />
    		</field>
    		<field name="version" type="integer">
    			<bind-xml name="version" node="attribute" />
    		</field>
    		<field name="rue" type="string">
    			<bind-xml name="rue" node="attribute" />
    		</field>
    		<field name="ville" type="string">
    			<bind-xml name="ville" node="attribute" />
    		</field>
    	</class>
    </mapping>


    J'ai un bean Personne et un bean Adresse. Personne contient une liste de Adresse. Le problème est que je ne sais pas comment faire pour ignorer le noeud <adresses> et récupérer directement la liste des adresses se trouvant en dessous.

    Si j'essaie comme indiqué

    J'ai cette erreur

    org.xml.sax.SAXException: unable to find FieldDescriptor for 'adresses' in ClassDescriptor of personne
    at org.exolab.castor.xml.UnmarshalHandler.startElement(UnmarshalHandler.java:1791)
    at org.exolab.castor.xml.UnmarshalHandler.startElement(UnmarshalHandler.java:1292)
    at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:605)
    at hibernate.test.bean.CastorTest.testCastor(CastorTest.java:22)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at junit.framework.TestCase.runTest(TestCase.java:164)
    at junit.framework.TestCase.runBare(TestCase.java:130)
    at junit.framework.TestResult$1.protect(TestResult.java:106)
    at junit.framework.TestResult.runProtected(TestResult.java:124)
    at junit.framework.TestResult.run(TestResult.java:109)
    at junit.framework.TestCase.run(TestCase.java:120)
    at junit.framework.TestSuite.runTest(TestSuite.java:230)
    at junit.framework.TestSuite.run(TestSuite.java:225)
    at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

    Si quelqu'un a une idée ...

    Merci d'avance

  2. #2
    Membre à l'essai
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    11
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2008
    Messages : 11
    Points : 11
    Points
    11
    Par défaut
    Salut,

    je ma pose la même question que toi. As-tu résolu ton problème ?

    Merci d'avance.
    al.ex

  3. #3
    Membre à l'essai
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    11
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2008
    Messages : 11
    Points : 11
    Points
    11
    Par défaut
    10 mns après je trouve la solution.
    il faut spécifier container="false" pour le field adresses.
    En gras dans l'exemple :
    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
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    <mapping>
    	<class name="test.bean.Personne">
    		<map-to xml="personne" />
    		<field name="id" type="string">
    			<bind-xml name="id" node="attribute" />
    		</field>
    		<field name="version" type="integer">
    			<bind-xml name="version" node="attribute" />
    		</field>
    		<field name="prenom" type="string">
    			<bind-xml name="prenom" node="attribute" />
    		</field>
    		<field name="nom" type="string">
    			<bind-xml name="nom" node="attribute" />
    		</field>
    		<field name="adresses" 
                            collection="arraylist" 
                            type="test.bean.Adresse"
                            container="false">
    			<bind-xml name="adresse" node="element" />
    		</field>
    	</class>
    	<class name="test.bean.Adresse">
                   <map-to xml="adresse " />
    		<field name="id" type="string">
    			<bind-xml name="id" node="attribute" />
    		</field>
    		<field name="version" type="integer">
    			<bind-xml name="version" node="attribute" />
    		</field>
    		<field name="rue" type="string">
    			<bind-xml name="rue" node="attribute" />
    		</field>
    		<field name="ville" type="string">
    			<bind-xml name="ville" node="attribute" />
    		</field>
    	</class>
    </mapping>

Discussions similaires

  1. [XML] [DOM XML] editer un noeud dans un fichier XML
    Par nina.b dans le forum Bibliothèques et frameworks
    Réponses: 2
    Dernier message: 17/09/2009, 12h22
  2. Réponses: 5
    Dernier message: 03/11/2006, 18h38
  3. inserer un noeud dans un arbre xml
    Par ujoodha dans le forum XML/XSL et SOAP
    Réponses: 1
    Dernier message: 27/01/2006, 23h29
  4. Enlver un noeud dans une structure XML
    Par Sharingan dans le forum ASP
    Réponses: 4
    Dernier message: 20/12/2004, 08h08
  5. [VB.NET] [XML] Suppression d'un noeud dans un fichier XML
    Par Hoegaarden dans le forum Windows Forms
    Réponses: 2
    Dernier message: 24/09/2004, 11h24

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