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 :

Parcours et manipulation d'un fichier XMI


Sujet :

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

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre actif
    Femme Profil pro
    Étudiant
    Inscrit en
    Mars 2014
    Messages
    83
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2014
    Messages : 83
    Par défaut Parcours et manipulation d'un fichier XMI
    Bonjour,
    j'ai exporté cet fichier a partir d'un diagramme de classe. le probléme c'est lorsque je parse cet fichier sous le nom (untitled.xmi) ça marche pas est c'est indiqué comme erreur mais lorsque je change l'extension vers (.XML) le code parait sans erreur mais en exécution la méthode qui permet d'extraire des informations de a partir ce fichier ne marche pas (pas d'affichage).
    voici le fichier XMI:
    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
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    <?xml version = "1.0" encoding = "UTF-8"?>
    <XMI xmi.version = "1.1" xmlns:UML="href://org.omg/UML/1.3">
    <XMI.header>
      <XMI.documentation>
        <XMI.owner></XMI.owner>
        <XMI.contact></XMI.contact>
        <XMI.exporter>StarUML.XMI-Addin</XMI.exporter>
        <XMI.exporterVersion>1.0</XMI.exporterVersion>
        <XMI.notice></XMI.notice>
      </XMI.documentation>
      <XMI.metamodel xmi.name = "UML" xmi.version = "1.3"/>
     </XMI.header>
    <XMI.content>
    <UML:Model xmi.id="UMLProject.1">
      <UML:Namespace.ownedElement>
        <UML:Model xmi.id="UMLModel.2" name="Use Case Model" visibility="public" isSpecification="false" namespace="UMLProject.1" isRoot="false" isLeaf="false" isAbstract="false">
          <UML:Namespace.ownedElement>
            <UML:Stereotype xmi.id="X.59" name="useCaseModel" extendedElement="UMLModel.2"/>
          </UML:Namespace.ownedElement>
        </UML:Model>
        <UML:Model xmi.id="UMLModel.3" name="Analysis Model" visibility="public" isSpecification="false" namespace="UMLProject.1" isRoot="false" isLeaf="false" isAbstract="false">
          <UML:Namespace.ownedElement>
            <UML:Stereotype xmi.id="X.60" name="analysisModel" extendedElement="UMLModel.3"/>
          </UML:Namespace.ownedElement>
        </UML:Model>
        <UML:Model xmi.id="UMLModel.4" name="Design Model" visibility="public" isSpecification="false" namespace="UMLProject.1" isRoot="false" isLeaf="false" isAbstract="false">
          <UML:Namespace.ownedElement>
            <UML:Class xmi.id="UMLClass.5" name="vehicule" visibility="public" isSpecification="false" namespace="UMLModel.4" isRoot="false" isLeaf="false" isAbstract="false" participant="UMLAssociationEnd.20 UMLAssociationEnd.31" isActive="false">
              <UML:Classifier.feature>
                <UML:Attribute xmi.id="UMLAttribute.6" name="marque" visibility="public" isSpecification="false" ownerScope="instance" changeability="changeable" targetScope="instance" type="" owner="UMLClass.5"/>
                <UML:Attribute xmi.id="UMLAttribute.7" name="modele" visibility="public" isSpecification="false" ownerScope="instance" changeability="changeable" targetScope="instance" type="" owner="UMLClass.5"/>
                <UML:Attribute xmi.id="UMLAttribute.8" name="couleur" visibility="public" isSpecification="false" ownerScope="instance" changeability="changeable" targetScope="instance" type="" owner="UMLClass.5"/>
              </UML:Classifier.feature>
            </UML:Class>
            <UML:Class xmi.id="UMLClass.9" name="capteur" visibility="public" isSpecification="false" namespace="UMLModel.4" isRoot="false" isLeaf="false" isAbstract="false" participant="UMLAssociationEnd.16 UMLAssociationEnd.19" isActive="false">
              <UML:Classifier.feature>
                <UML:Attribute xmi.id="UMLAttribute.10" name="id_capteur" visibility="public" isSpecification="false" ownerScope="instance" changeability="changeable" targetScope="instance" type="" owner="UMLClass.9"/>
              </UML:Classifier.feature>
            </UML:Class>
            <UML:Class xmi.id="UMLClass.11" name="mesure" visibility="public" isSpecification="false" namespace="UMLModel.4" isRoot="false" isLeaf="false" isAbstract="false" participant="UMLAssociationEnd.17 UMLAssociationEnd.30 UMLAssociationEnd.33" isActive="false">
              <UML:Classifier.feature>
                <UML:Attribute xmi.id="UMLAttribute.12" name="type" visibility="public" isSpecification="false" ownerScope="instance" changeability="changeable" targetScope="instance" type="" owner="UMLClass.11"/>
                <UML:Attribute xmi.id="UMLAttribute.13" name="instant" visibility="public" isSpecification="false" ownerScope="instance" changeability="changeable" targetScope="instance" type="" owner="UMLClass.11"/>
                <UML:Attribute xmi.id="UMLAttribute.14" name="intervalle" visibility="public" isSpecification="false" ownerScope="instance" changeability="changeable" targetScope="instance" type="" owner="UMLClass.11"/>
              </UML:Classifier.feature>
            </UML:Class>
            <UML:Association xmi.id="UMLAssociation.15" name="" visibility="public" isSpecification="false" namespace="UMLModel.4">
              <UML:Association.connection>
                <UML:AssociationEnd xmi.id="UMLAssociationEnd.16" name="" visibility="public" isSpecification="false" isNavigable="true" ordering="unordered" aggregation="none" targetScope="instance" changeability="changeable" association="UMLAssociation.15" type="UMLClass.9"/>
                <UML:AssociationEnd xmi.id="UMLAssociationEnd.17" name="" visibility="public" isSpecification="false" isNavigable="true" ordering="unordered" aggregation="none" targetScope="instance" changeability="changeable" association="UMLAssociation.15" type="UMLClass.11"/>
              </UML:Association.connection>
            </UML:Association>
            <UML:Association xmi.id="UMLAssociation.18" name="" visibility="public" isSpecification="false" namespace="UMLModel.4">
              <UML:Association.connection>
                <UML:AssociationEnd xmi.id="UMLAssociationEnd.19" name="" visibility="public" isSpecification="false" isNavigable="true" ordering="unordered" aggregation="none" targetScope="instance" changeability="changeable" association="UMLAssociation.18" type="UMLClass.9"/>
                <UML:AssociationEnd xmi.id="UMLAssociationEnd.20" name="" visibility="public" isSpecification="false" isNavigable="true" ordering="unordered" aggregation="none" targetScope="instance" changeability="changeable" association="UMLAssociation.18" type="UMLClass.5"/>
              </UML:Association.connection>
            </UML:Association>
            <UML:Class xmi.id="UMLClass.21" name="alerte" visibility="public" isSpecification="false" namespace="UMLModel.4" isRoot="false" isLeaf="false" isAbstract="false" participant="UMLAssociationEnd.37 UMLAssociationEnd.42 UMLAssociationEnd.48" isActive="false">
              <UML:Classifier.feature>
                <UML:Attribute xmi.id="UMLAttribute.22" name="instant" visibility="public" isSpecification="false" ownerScope="instance" changeability="changeable" targetScope="instance" type="" owner="UMLClass.21"/>
                <UML:Attribute xmi.id="UMLAttribute.23" name="intervalle" visibility="public" isSpecification="false" ownerScope="instance" changeability="changeable" targetScope="instance" type="" owner="UMLClass.21"/>
                <UML:Attribute xmi.id="UMLAttribute.24" name="type" visibility="public" isSpecification="false" ownerScope="instance" changeability="changeable" targetScope="instance" type="" owner="UMLClass.21"/>
              </UML:Classifier.feature>
            </UML:Class>
            <UML:Class xmi.id="UMLClass.25" name="SAGT" visibility="public" isSpecification="false" namespace="UMLModel.4" isRoot="false" isLeaf="false" isAbstract="false" participant="UMLAssociationEnd.34 UMLAssociationEnd.36" isActive="false">
              <UML:Classifier.feature>
                <UML:Attribute xmi.id="UMLAttribute.26" name="identifiant" visibility="public" isSpecification="false" ownerScope="instance" changeability="changeable" targetScope="instance" type="" owner="UMLClass.25"/>
                <UML:Operation xmi.id="UMLOperation.27" name="analysermesure" visibility="public" isSpecification="false" ownerScope="instance" isQuery="false" concurrency="sequential" isRoot="false" isLeaf="false" isAbstract="false" specification="" owner="UMLClass.25"/>
                <UML:Operation xmi.id="UMLOperation.28" name="produirealerte" visibility="public" isSpecification="false" ownerScope="instance" isQuery="false" concurrency="sequential" isRoot="false" isLeaf="false" isAbstract="false" specification="" owner="UMLClass.25"/>
              </UML:Classifier.feature>
            </UML:Class>
            <UML:Association xmi.id="UMLAssociation.29" name="" visibility="public" isSpecification="false" namespace="UMLModel.4">
              <UML:Association.connection>
                <UML:AssociationEnd xmi.id="UMLAssociationEnd.30" name="" visibility="public" isSpecification="false" isNavigable="true" ordering="unordered" aggregation="none" targetScope="instance" changeability="changeable" association="UMLAssociation.29" type="UMLClass.11"/>
                <UML:AssociationEnd xmi.id="UMLAssociationEnd.31" name="" visibility="public" isSpecification="false" isNavigable="true" ordering="unordered" aggregation="none" targetScope="instance" changeability="changeable" association="UMLAssociation.29" type="UMLClass.5"/>
              </UML:Association.connection>
            </UML:Association>
            <UML:Association xmi.id="UMLAssociation.32" name="" visibility="public" isSpecification="false" namespace="UMLModel.4">
              <UML:Association.connection>
                <UML:AssociationEnd xmi.id="UMLAssociationEnd.33" name="" visibility="public" isSpecification="false" isNavigable="true" ordering="unordered" aggregation="none" targetScope="instance" changeability="changeable" association="UMLAssociation.32" type="UMLClass.11"/>
                <UML:AssociationEnd xmi.id="UMLAssociationEnd.34" name="" visibility="public" isSpecification="false" isNavigable="true" ordering="unordered" aggregation="none" targetScope="instance" changeability="changeable" association="UMLAssociation.32" type="UMLClass.25"/>
              </UML:Association.connection>
            </UML:Association>
            <UML:Association xmi.id="UMLAssociation.35" name="" visibility="public" isSpecification="false" namespace="UMLModel.4">
              <UML:Association.connection>
                <UML:AssociationEnd xmi.id="UMLAssociationEnd.36" name="" visibility="public" isSpecification="false" isNavigable="true" ordering="unordered" aggregation="none" targetScope="instance" changeability="changeable" association="UMLAssociation.35" type="UMLClass.25"/>
                <UML:AssociationEnd xmi.id="UMLAssociationEnd.37" name="" visibility="public" isSpecification="false" isNavigable="true" ordering="unordered" aggregation="none" targetScope="instance" changeability="changeable" association="UMLAssociation.35" type="UMLClass.21"/>
              </UML:Association.connection>
            </UML:Association>
            <UML:Class xmi.id="UMLClass.38" name="PMV" visibility="public" isSpecification="false" namespace="UMLModel.4" isRoot="false" isLeaf="false" isAbstract="false" participant="UMLAssociationEnd.43" isActive="false">
              <UML:Classifier.feature>
                <UML:Attribute xmi.id="UMLAttribute.39" name="identifiant" visibility="public" isSpecification="false" ownerScope="instance" changeability="changeable" targetScope="instance" type="" owner="UMLClass.38"/>
                <UML:Attribute xmi.id="UMLAttribute.40" name="emplacement" visibility="public" isSpecification="false" ownerScope="instance" changeability="changeable" targetScope="instance" type="" owner="UMLClass.38"/>
              </UML:Classifier.feature>
            </UML:Class>
            <UML:Association xmi.id="UMLAssociation.41" name="" visibility="public" isSpecification="false" namespace="UMLModel.4">
              <UML:Association.connection>
                <UML:AssociationEnd xmi.id="UMLAssociationEnd.42" name="" visibility="public" isSpecification="false" isNavigable="true" ordering="unordered" aggregation="none" targetScope="instance" changeability="changeable" association="UMLAssociation.41" type="UMLClass.21"/>
                <UML:AssociationEnd xmi.id="UMLAssociationEnd.43" name="" visibility="public" isSpecification="false" isNavigable="true" ordering="unordered" aggregation="none" targetScope="instance" changeability="changeable" association="UMLAssociation.41" type="UMLClass.38"/>
              </UML:Association.connection>
            </UML:Association>
            <UML:Class xmi.id="UMLClass.44" name="evenement" visibility="public" isSpecification="false" namespace="UMLModel.4" isRoot="false" isLeaf="false" isAbstract="false" specialization="UMLGeneralization.55 UMLGeneralization.56" participant="UMLAssociationEnd.49" isActive="false">
              <UML:Classifier.feature>
                <UML:Attribute xmi.id="UMLAttribute.45" name="instant" visibility="public" isSpecification="false" ownerScope="instance" changeability="changeable" targetScope="instance" type="" owner="UMLClass.44"/>
                <UML:Attribute xmi.id="UMLAttribute.46" name="intervalle" visibility="public" isSpecification="false" ownerScope="instance" changeability="changeable" targetScope="instance" type="" owner="UMLClass.44"/>
              </UML:Classifier.feature>
            </UML:Class>
            <UML:Association xmi.id="UMLAssociation.47" name="" visibility="public" isSpecification="false" namespace="UMLModel.4">
              <UML:Association.connection>
                <UML:AssociationEnd xmi.id="UMLAssociationEnd.48" name="" visibility="public" isSpecification="false" isNavigable="true" ordering="unordered" aggregation="none" targetScope="instance" changeability="changeable" association="UMLAssociation.47" type="UMLClass.21"/>
                <UML:AssociationEnd xmi.id="UMLAssociationEnd.49" name="" visibility="public" isSpecification="false" isNavigable="true" ordering="unordered" aggregation="none" targetScope="instance" changeability="changeable" association="UMLAssociation.47" type="UMLClass.44"/>
              </UML:Association.connection>
            </UML:Association>
            <UML:Class xmi.id="UMLClass.50" name="TDM" visibility="public" isSpecification="false" namespace="UMLModel.4" isRoot="false" isLeaf="false" isAbstract="false" generalization="UMLGeneralization.55" isActive="false">
              <UML:Classifier.feature>
                <UML:Attribute xmi.id="UMLAttribute.51" name="matricule_vehicule" visibility="public" isSpecification="false" ownerScope="instance" changeability="changeable" targetScope="instance" type="" owner="UMLClass.50"/>
              </UML:Classifier.feature>
            </UML:Class>
            <UML:Class xmi.id="UMLClass.52" name="incident" visibility="public" isSpecification="false" namespace="UMLModel.4" isRoot="false" isLeaf="false" isAbstract="false" generalization="UMLGeneralization.56" isActive="false">
              <UML:Classifier.feature>
                <UML:Attribute xmi.id="UMLAttribute.53" name="type" visibility="public" isSpecification="false" ownerScope="instance" changeability="changeable" targetScope="instance" type="" owner="UMLClass.52"/>
                <UML:Attribute xmi.id="UMLAttribute.54" name="gravite" visibility="public" isSpecification="false" ownerScope="instance" changeability="changeable" targetScope="instance" type="" owner="UMLClass.52"/>
              </UML:Classifier.feature>
            </UML:Class>
            <UML:Generalization xmi.id="UMLGeneralization.55" name="" visibility="public" isSpecification="false" namespace="UMLModel.4" discriminator="" child="UMLClass.50" parent="UMLClass.44"/>
            <UML:Generalization xmi.id="UMLGeneralization.56" name="" visibility="public" isSpecification="false" namespace="UMLModel.4" discriminator="" child="UMLClass.52" parent="UMLClass.44"/>
            <UML:Stereotype xmi.id="X.61" name="designModel" extendedElement="UMLModel.4"/>
            <UML:Stereotype xmi.id="X.62" name="observed-element" extendedElement="UMLClass.5"/>
            <UML:Stereotype xmi.id="X.66" name="observer" extendedElement="UMLClass.9"/>
            <UML:Stereotype xmi.id="X.68" name="measure" extendedElement="UMLClass.11"/>
            <UML:Stereotype xmi.id="X.72" name="alert" extendedElement="UMLClass.21"/>
            <UML:Stereotype xmi.id="X.76" name="controler" extendedElement="UMLClass.25"/>
            <UML:Stereotype xmi.id="X.78" name="actuator" extendedElement="UMLClass.38"/>
            <UML:Stereotype xmi.id="X.81" name="event" extendedElement="UMLClass.44"/>
          </UML:Namespace.ownedElement>
        </UML:Model>
        <UML:Model xmi.id="UMLModel.57" name="Implementation Model" visibility="public" isSpecification="false" namespace="UMLProject.1" isRoot="false" isLeaf="false" isAbstract="false">
          <UML:Namespace.ownedElement>
            <UML:Stereotype xmi.id="X.87" name="implementationModel" extendedElement="UMLModel.57"/>
          </UML:Namespace.ownedElement>
        </UML:Model>
        <UML:Model xmi.id="UMLModel.58" name="Deployment Model" visibility="public" isSpecification="false" namespace="UMLProject.1" isRoot="false" isLeaf="false" isAbstract="false">
          <UML:Namespace.ownedElement>
            <UML:Stereotype xmi.id="X.88" name="deploymentModel" extendedElement="UMLModel.58"/>
          </UML:Namespace.ownedElement>
        </UML:Model>
      </UML:Namespace.ownedElement>
    </UML:Model>
    <UML:TaggedValue xmi.id="X.63" tag="ordering" value="unordered" modelElement="UMLAttribute.6"/>
    <UML:TaggedValue xmi.id="X.64" tag="ordering" value="unordered" modelElement="UMLAttribute.7"/>
    <UML:TaggedValue xmi.id="X.65" tag="ordering" value="unordered" modelElement="UMLAttribute.8"/>
    <UML:TaggedValue xmi.id="X.67" tag="ordering" value="unordered" modelElement="UMLAttribute.10"/>
    <UML:TaggedValue xmi.id="X.69" tag="ordering" value="unordered" modelElement="UMLAttribute.12"/>
    <UML:TaggedValue xmi.id="X.70" tag="ordering" value="unordered" modelElement="UMLAttribute.13"/>
    <UML:TaggedValue xmi.id="X.71" tag="ordering" value="unordered" modelElement="UMLAttribute.14"/>
    <UML:TaggedValue xmi.id="X.73" tag="ordering" value="unordered" modelElement="UMLAttribute.22"/>
    <UML:TaggedValue xmi.id="X.74" tag="ordering" value="unordered" modelElement="UMLAttribute.23"/>
    <UML:TaggedValue xmi.id="X.75" tag="ordering" value="unordered" modelElement="UMLAttribute.24"/>
    <UML:TaggedValue xmi.id="X.77" tag="ordering" value="unordered" modelElement="UMLAttribute.26"/>
    <UML:TaggedValue xmi.id="X.79" tag="ordering" value="unordered" modelElement="UMLAttribute.39"/>
    <UML:TaggedValue xmi.id="X.80" tag="ordering" value="unordered" modelElement="UMLAttribute.40"/>
    <UML:TaggedValue xmi.id="X.82" tag="ordering" value="unordered" modelElement="UMLAttribute.45"/>
    <UML:TaggedValue xmi.id="X.83" tag="ordering" value="unordered" modelElement="UMLAttribute.46"/>
    <UML:TaggedValue xmi.id="X.84" tag="ordering" value="unordered" modelElement="UMLAttribute.51"/>
    <UML:TaggedValue xmi.id="X.85" tag="ordering" value="unordered" modelElement="UMLAttribute.53"/>
    <UML:TaggedValue xmi.id="X.86" tag="ordering" value="unordered" modelElement="UMLAttribute.54"/>
    </XMI.content>
    </XMI>
    voici le code de la fonction: merci de m'aider c'est très urgent .
    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
     
    public class Affichage {
        public static void main(String[] args) {
             try {
                affichage();
             } catch(ClassNotFoundException e) {
                e.printStackTrace();
             }
        }
        public static void affichage() throws ClassNotFoundException {
     
    		/* Création du parseur */SAXBuilder builder = new SAXBuilder();
     
    		File fichierxmi = new File("Untitled.xmi");
    		Document document; 
     
     
    		try {
    			/* Parsing du fichier */
    			document = builder.build(fichierxmi);
    			 Namespace ns = Namespace.getNamespace("UML", "org.omg.xmi.namespace.UML");
    			/* Racine du document XML : dans notre cas <diagramme> */
    		Element rootNode = document.getRootElement();
    		List<Element> row = rootNode.getChildren("XMI.content");
     
    		List<String> temps = new ArrayList<String>();
    	    List<String> autres = new ArrayList<String>();
    		parserFichier(row,temps,autres);
    		window(temps,autres);
    		}
    	 catch (JDOMException e) {
    		e.printStackTrace(System.out);
    	} catch (IOException e) {
    		e.printStackTrace(System.out);
    	}
     
     
     
     
    	}
    	public static void addOnce(List<String> list, String text) {
    		   if ( !list.contains(text) ) list.add(text);
    		}
    	public static void collect(List<String> list, Element elmt, boolean addText) {
     
    	    if ( addText ) {
    	        addOnce(list, elmt.getName()+ "  nom=" +elmt.getText());
    	    }
    	    else{ addOnce(list, elmt.getName()); }
    	}
     
    	public static void parserFichier( List<Element> row,List<String> temps, List<String> autres) throws ClassNotFoundException{
    		for 
    			 ( Element infoElenemt : row){
    		        List column = infoElenemt.getChildren("UML.Model");
    		       for (int j = 0; j < column.size(); j++) {
    		          Element infoElement1 = (Element) column.get(j);
    		          List column1 = infoElenemt.getChildren("UML:Namespace.ownedElement");
    		          for (int h = 0; h<column1.size(); h++){
    		        	  Element infoElement2 = (Element) column1.get(h);
     
    		        	  List column2 = infoElement2.getChildren("UML:Class");
     
    		        		  if("instant".equals(infoElement2.getName())||("intervalle".equals(infoElement2.getName()))||("event".equals(infoElement2.getName()))){
    			        		  collect( temps, infoElement2, column2.isEmpty() );
    			        		  for (int F = 0; h<column2.size(); F++){
    			        			  Element infoElement3=(Element) column2.get(F);
    			        			  collect(temps,infoElement3,column1.equals(null));
    					             }
    			        	  }
    		        	  }
     
    		          }
     
    		        }
    	      }

  2. #2
    Membre actif
    Femme Profil pro
    Étudiant
    Inscrit en
    Mars 2014
    Messages
    83
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2014
    Messages : 83
    Par défaut
    Bonjour,
    j'ai créé un code pour l'extraction des informations a partir d'un fichier xmi. il parait juste mais lors de l'exécution pas de résultat. merci bien pour votre aide
    je vous montres le code de parsage:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    SAXBuilder builder = new SAXBuilder();
     
    		File fichierxmi = new File("Untitled.xmi");
    		Document document;
    puis je pointe au UML:Namespace.ownedElement comme ça:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    List <Element>column = rootNode.getChildren("UML:Namespace.ownedElement");
    puis je fais une méthode pour le parcours et l'extraction des informations:

    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
    public static void parserFichier( List<Element> column,List<String> temps, List<String> autres) throws ClassNotFoundException{
    		 Namespace ns = Namespace.getNamespace("UML", "org.omg.xmi.namespace.UML");
     
    		          for (Element infoElenemt11 : column){
    		        	  List <Element>column2 = infoElenemt11.getChildren("UML:Class");
    		        		  if("instant".equals(infoElenemt11 .getAttribute("name", ns))||("intervalle".equals(infoElenemt11 .getAttribute("name",ns))||("event".equals(infoElenemt11 .getAttribute("name",ns))))){
    			        		  collect( temps,infoElenemt11 , column.isEmpty() );  
    			        	  }
    		        		  else{ 
    		        			  collect( autres,infoElenemt11 , column2.isEmpty() );
    		        			  if(!column2.isEmpty()){
    		        				  parserFichier( column2, temps, autres ); 
    		        			      }
    		        			  }
    		        		  }
    		        	  }
    la méthode collect et addOnce sont les suivants:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    public static void addOnce(List<String> list, String string) {
    		   if ( !list.contains(string) ) list.add(string);
    		}
    	public static void collect(List<String> list, Element elmt, boolean addText) {
     
    	    if ( addText ) {
    	        addOnce(list, elmt.getAttribute("name")+ "  nom=" +elmt.getText());
    	    }
    	    else{ addOnce(list, elmt.getName()); }
    	}
    et enfin je fais appel au deux tableaux pour afficher leurs contenu
    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
    public static void window( List<String> temps, List<String> autres){
    StringBuilder texte = new StringBuilder(" ~~concepts décrivent le temps ~~"); 
    		 texte.append( "\n" );
    		StringBuilder texte1 = new StringBuilder("~~concepts décrivent le domaine ~~"); 
    		 texte1.append( "\n" );
    		for( String temp :  temps ) {
    		    texte.append( "\n" ); // pour passer à la ligne suivante
    		    texte.append( temp ); // le texte de la ligne
    		}
     
    		// et à la fin :
    		grandeZone.setText(texte.toString());
    		for( String temp1 :  autres ) {
    		    texte1.append( "\n" );
    		    texte1.append( temp1); // le texte de la ligne
    		}
    		// et à la fin :
    		grandeZone1.setText(texte1.toString());}
    s'il vous plait je besoin de vos expériences parce que je suis perdue et je passe presque trois jours dans ce le même point

  3. #3
    Membre Expert Avatar de tsuji
    Inscrit en
    Octobre 2011
    Messages
    1 558
    Détails du profil
    Informations forums :
    Inscription : Octobre 2011
    Messages : 1 558
    Par défaut
    Je n'arrive pas à lire très loin; juste quelque lignes et là déjà des erreurs fondamentionales qui s'assurent que ce n'est pas la peine de lire plus loin.
    Ligne 21 du premier post
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Namespace ns = Namespace.getNamespace("UML", "org.omg.xmi.namespace.UML");
    Qu'est-ce qu'on lit du xml (toujours du premier post, ligne 2) ?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <XMI xmi.version = "1.1" xmlns:UML="href://org.omg/UML/1.3">
    Est-ce que ça semble bon ?

    Et puis, ligne 55
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    List column = infoElenemt.getChildren("UML.Model");
    Vous arrivez à trouver UML.Model quelque part dans le xml ? Voyons. Si je la réecris comme
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    List column = infoElenemt.getChildren("Model", ns);
    ça vous inspire un peu ou pas du tout ?

  4. #4
    Membre actif
    Femme Profil pro
    Étudiant
    Inscrit en
    Mars 2014
    Messages
    83
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2014
    Messages : 83
    Par défaut
    Citation Envoyé par tsuji Voir le message
    Je n'arrive pas à lire très loin; juste quelque lignes et là déjà des erreurs fondamentionales qui s'assurent que ce n'est pas la peine de lire plus loin.
    Ligne 21 du premier post

    Qu'est-ce qu'on lit du xml (toujours du premier post, ligne 2) ?

    Est-ce que ça semble bon ?

    Et puis, ligne 55

    Vous arrivez à trouver UML.Model quelque part dans le xml ? Voyons. Si je la réecris comme
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    List column = infoElenemt.getChildren("Model", ns);
    ça vous inspire un peu ou pas du tout ?
    Merci beaucoup pour votre réponse
    Concernant remarque 1: c'est l'appel d'un namespace car je trouve dans des forums ce code et je trouve qui est très intéressant pour un fichier XMI.
    remarque 2: Element rootNode = document.getRootElement(); se pointe vers :<XMI xmi.version = "1.1" xmlns:UML="href://org.omg/UML/1.3">
    Le fichier xmi c'est un fichier exporté à partir d'un diagramme de classe en startUML.
    En résumé: je pointe vers <UML:Class> qui est l'enfant de <"UML:Namespace.ownedElement"> ce qui est l'enfant de <"UML:Model>.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    document.getDescendants(Filters.element("Class", ns));
    Mais comment je peux sauvegarder les listes dans un variable pour parcourir enfin ce variable pour extraire les attributs et les sous éléments.dans des autres forums je trouve qu'on peut accéder directement aux éléments qu'on besoin. Pour résoudre ça j'ai créé comme suit:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    List<Element> row1=(List<Element>) document.getDescendants(Filters.element("Class", ns));
    mais malheureusement il m'oblige d'ajouter des messages de warninngs pour row1 et même pour la méthode affichage()
    S’il vous plait aidez-moi a corrigé ça car malheureusement je suis débutante en java et je pense que je commence par des choses difficiles?

    :'(

  5. #5
    Membre Expert Avatar de tsuji
    Inscrit en
    Octobre 2011
    Messages
    1 558
    Détails du profil
    Informations forums :
    Inscription : Octobre 2011
    Messages : 1 558
    Par défaut
    Concernant remarque 1: c'est l'appel d'un namespace car je trouve dans des forums ce code et je trouve qui est très intéressant pour un fichier XMI.
    Il faut être candide et sur le point, ne faut-il pas ? Dites-nous ce que vous la prenez ma "remarque 1" : faut-il prendre quelque action sur votre code ou pas, oui ou non ? Si oui, qu'avez-vous pris comme action ? Il se peut que vous pensez le code est tout bon parce que "vous trouvez dans des forums" et vous trouvez le "très intéressant". Mais, au moins, faites le point : sinon, on ne sait pas qu'est-ce que vous avez fait de suite.

  6. #6
    Membre actif
    Femme Profil pro
    Étudiant
    Inscrit en
    Mars 2014
    Messages
    83
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2014
    Messages : 83
    Par défaut
    Bonjour,
    Vraiment je ne connais pas c'est quoi l'utilité de namespace mais lorsque je cherche sur des forums comment parser un fichier xmi/xml. je trouve comme des réponses de faire appel a un namespace c'est tous.
    pour le moment j’enlève ce namespace et je faire un programme pour parcourir un fichier xmi/xml . dans la méthode parserFichier je pense que ma problème et a ce niveau parce que le but et de remplir deux ArrayLists chacun avec des éléments spécifiques mais lors de l'appel de ces deux ArrayList je trouve qu'ils sont vides. Voici le code complet que je fais .s'il vous plait aidez-moi a corrigé les fautes et a parcourir correctement ce fichier. je vous invite a se concentré aux méthodes parserFichier et collect(). je suis perdue car je ne connais pas l'erreur. l'erreur parait facile pour vous les experts. merci bien pour votre aide et aussi pour votre patience

    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
    109
    110
    111
    112
    113
    public class fichier {
        public static void main(String[] args) {
             try {
                affichage();
             } catch(ClassNotFoundException e) {
                e.printStackTrace();
             }
        }
        public static void affichage() throws ClassNotFoundException {
           SAXBuilder builder = new SAXBuilder();
    		File fichierxmi = new File("exercice.xmi");
    		Document document; 
    		try {
    			document = builder.build(fichierxmi);
    		Element rootNode = document.getRootElement();
    		List<Element> row = rootNode.getChildren("XMI.content");
    		List<String> temps = new ArrayList<String>();
    	    List<String> autres = new ArrayList<String>();
    		parserFichier(row,temps,autres);
    		window(temps,autres);
    		}
    	 catch (JDOMException e) {
    		e.printStackTrace(System.out);
    	} catch (IOException e) {
    		e.printStackTrace(System.out);
    	}
    	}
        public static void addOnce(List<String> list, String text) {
    		   if ( !list.contains(text) ) list.add(text);
    		}
    	public static void collect(List<String> list, Element elmt, boolean addText) {
    	    if ( addText ) {
    	        addOnce(list, elmt.getAttribute("name").getName()+ "  nom=" +elmt.getText());
    	    }
    	    else{ addOnce(list, elmt.getAttribute("name").getName()); }
    	}
     
    	public static void parserFichier( List<Element> row,List<String> temps, List<String> autres) throws ClassNotFoundException{
    		for 
    			 ( Element infoElenemt : row){
    		        List<Element> column = infoElenemt.getChildren("UML:Model");
    		       for (int j = 0; j < column.size(); j++) {
    		          Element infoElement1 = (Element) column.get(j);
    		          List<Element> column1 = infoElement1.getChildren("UML:Namespace.ownedElement");
    		          for (int h = 0; h<column1.size(); h++){
    		        	  Element infoElement2 = (Element) column1.get(h);
    		        	  List<Element> column2 = infoElement2.getChildren("UML:Class");
    		        	  for (Element infoElenemt11 :column ){
    		        		  if("instant".equals(infoElenemt11 .getAttribute("name"))||("intervalle".equals(infoElenemt11 .getAttribute("name"))||("event".equals(infoElenemt11 .getAttribute("name"))))){
    			        		  collect( temps,infoElenemt11 , column.isEmpty() );  
    			        	  }
    		        		  else{ collect( autres,infoElenemt11 , column.isEmpty() );}
     
    			        	  }
    		        	  }
     
    		          }
     
    		        }
    	      }
    	public static void window( List<String> temps, List<String> autres){
    		int tailleInitiale = 20;
    		Font fonte;
    		JScrollPane texteAsc;
    		JScrollPane texteAsc1;
    		JLabel label = new JLabel("Extraction de connaissances");
    		JFrame window=new JFrame("extraction connaissances"); 
    		JTextArea grandeZone = new JTextArea(7,10);
    		JTextArea grandeZone1 = new JTextArea(7, 10);
    		texteAsc = new JScrollPane(grandeZone);
    		texteAsc1 = new JScrollPane(grandeZone1);
    		JPanel container = new JPanel();
    		JPanel surfTotPanel = new JPanel();
    		JPanel surfTotPanel2 = new JPanel();
    		surfTotPanel.setLayout(new BoxLayout(surfTotPanel,BoxLayout.Y_AXIS));
    		Dimension dimension = new Dimension(320,500);
    		surfTotPanel.setPreferredSize(dimension);
    		surfTotPanel2.setLayout(new BoxLayout(surfTotPanel2,BoxLayout.Y_AXIS));
    		Dimension dimension2 = new Dimension(320,500);
    		surfTotPanel2.setPreferredSize(dimension2);
    		surfTotPanel.add(texteAsc1);
    		surfTotPanel2.add(texteAsc);
    		container.setLayout(new BorderLayout());
    		label.setHorizontalAlignment(JLabel.CENTER);
    		container.add(label, BorderLayout.NORTH);
    		container.add(surfTotPanel2, BorderLayout.EAST);
    		container.add(surfTotPanel,BorderLayout.WEST);
    		window.setContentPane(container);
    		window.setVisible(true);
    		window.setSize(800,500);
    		Font police = new Font("Andalus", Font.CENTER_BASELINE, 25);
    		label.setFont(police);
    		label.setForeground(Color.blue);
    		StringBuilder texte = new StringBuilder(" ~~concepts décrivent le temps ~~"); 
    		 texte.append( "\n" );
    		StringBuilder texte1 = new StringBuilder("~~concepts décrivent le domaine ~~"); 
    		 texte1.append( "\n" );
    		for( String temp :  temps ) {
    		    texte.append( "\n" ); 
    		    texte.append( temp ); 
    		    }
    		grandeZone.setText(texte.toString());
    		grandeZone.getColorModel();
    		for( String temp1 :  autres ) {
    		    texte1.append( "\n" );
    		    texte1.append( temp1); // le texte de la ligne
    		}
    		grandeZone1.setText(texte1.toString()); 
    		fonte = new Font("Andalus", Font.HANGING_BASELINE, tailleInitiale);
    		grandeZone.setFont(fonte);
    		grandeZone1.setFont(fonte);
    	}
    }

Discussions similaires

  1. fichier xmi
    Par jeff_! dans le forum XML/XSL et SOAP
    Réponses: 3
    Dernier message: 07/04/2006, 10h30
  2. Réponses: 10
    Dernier message: 27/02/2006, 16h55
  3. [fstream] Manipulation d'un fichier ...
    Par Zenol dans le forum SL & STL
    Réponses: 6
    Dernier message: 11/02/2006, 10h49
  4. manipulation d'un fichier indexé par un arbre b
    Par nemya_1 dans le forum Algorithmes et structures de données
    Réponses: 1
    Dernier message: 21/01/2006, 19h30
  5. Réponses: 4
    Dernier message: 31/07/2004, 11h14

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