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

Langage Perl Discussion :

Création d'un fichier XML à partir d'un autre fichier XML


Sujet :

Langage Perl

  1. #1
    Nouveau Candidat au Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Mars 2016
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2016
    Messages : 4
    Points : 1
    Points
    1
    Par défaut Création d'un fichier XML à partir d'un autre fichier XML
    Bonjour,

    Je dois écrire un script qui me permettrait de parser plusieurs fichiers xml (disons une trentaine, voire plus) et me donnerait à la sortie des fichiers xml simples en ne gardant seulement que certaines balises et leur contenu. Le but est en fait de "nettoyer" les xml de choses dont je n'ai pas besoin pour la suite.
    Voici l'exemple d'un fichier :

    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
    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
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-model href="file:///opt/grobid-grobid-parent-0.3.9/grobid-home/schemas/rng/Grobid.rng" schematypens="http://relaxng.org/ns/structure/1.0"?>
    <TEI
        xmlns="http://www.tei-c.org/ns/1.0">
        <teiHeader xml:lang="en">
            <fileDesc>
                <titleStmt>
                    <title level="a" type="main">Accounting for Member Deformations in the Determination of the Dynamic Behavior of Robot-Type Structures</title>
                </titleStmt>
                <publicationStmt>
                    <publisher/>
                    <availability status="unknown">
                        <licence/>
                    </availability>
                </publicationStmt>
                <sourceDesc>
                    <biblStruct>
                        <analytic>
                            <author>
                                <persName>
                                    <forename type="first">A</forename>
                                    <surname>Barraco</surname>
                                </persName>
                                <affiliation>
                                    <orgName type="institution">Ecole Nationale Sup~rieure d'Arts et Mbtiers</orgName>
                                    <address>
                                        <addrLine>151, Bd de l'HSpital</addrLine>
                                        <postCode>75640</postCode>
                                        <settlement>Paris Cedex 13</settlement>
                                        <country key="FR">France</country>
                                    </address>
                                </affiliation>
                            </author>
                            <author>
                                <persName>
                                    <forename type="first">B</forename>
                                    <surname>Cuny</surname>
                                </persName>
                                <affiliation>
                                    <orgName type="institution">Ecole Nationale Sup~rieure d'Arts et Mbtiers</orgName>
                                    <address>
                                        <addrLine>151, Bd de l'HSpital</addrLine>
                                        <postCode>75640</postCode>
                                        <settlement>Paris Cedex 13</settlement>
                                        <country key="FR">France</country>
                                    </address>
                                </affiliation>
                            </author>
                            <author>
                                <persName>
                                    <forename type="first">G</forename>
                                    <surname>Ishiomin</surname>
                                </persName>
                                <affiliation>
                                    <orgName type="institution">Ecole Nationale Sup~rieure d'Arts et Mbtiers</orgName>
                                    <address>
                                        <addrLine>151, Bd de l'HSpital</addrLine>
                                        <postCode>75640</postCode>
                                        <settlement>Paris Cedex 13</settlement>
                                        <country key="FR">France</country>
                                    </address>
                                </affiliation>
                            </author>
                            <title level="a" type="main">Accounting for Member Deformations in the Determination of the Dynamic Behavior of Robot-Type Structures</title>
                        </analytic>
                        <monogr>
                            <imprint>
                                <date/>
                            </imprint>
                        </monogr>
                        <note>283</note>
                    </biblStruct>
                </sourceDesc>
            </fileDesc>
            <profileDesc>
                <textClass>
                    <keywords>
                        <term>Dynamic equations</term>
                        <term>Mechanisms</term>
                        <term>Structural deformations</term>
                        <term>Finite elements</term>
                        <term>Robotics</term>
                    </keywords>
                </textClass>
                <abstract>
                    <p>Two themes are being investigated: development of conception , simulation and visualization tools for rigid body mechanisms , accounting for member deformations in the dynamic behavior of mechanical systems. The equations for the dynamic behavior of systems are established from the application of an updated Lagrangian method to finite element discretiza-tions.</p>
                </abstract>
            </profileDesc>
        </teiHeader>
        <text xml:lang="en">
            <body>
                <div>
                    <head n="1">Introduction</head>
                    <p>The purpose of this research is to integrate member deformation effects into the mechanical models used to analyse the dynamic behavior of robot-type structures. This approach is indeed justified by the utilization conditions of such systems which look forward to have a maximal weight moved in a minimal time by an as light as possible structure, while keeping high precision and repeatability in the movement. From a mechanical standpoint, we can distinguish two types of problems which account for deformations in two different ways: Problem Nr. 1: in most multiple-connected systems , the major loss of precision originates in the connexions themselves. They always show some flexibility, free play or friction which induces a poor output. Problem Nr. 2: in some multiple-connected systems , in addition to the above connexion located deformations, structural members also show significant deformations, so that the mechanical systems can be called fully flexible. From these two problems therefore originate two different topics of research: Topic Nr. 1: different mechanical models do exist for such systems. The research is then aimed at selecting the &quot;best&quot; model while elaborating user-oriented procedures that allow a simple usage of the chosen model. We have used Computer</p>
                    <figure>
                        <trash>Professor Guy Ishiomin graduated as engineer from the &quot;E cole Nationale Sup&amp;ieure d'Arts &amp; M&amp;iers&quot; in 1970. He has been a Computer Science Prolessor at E.N.S.A.M, since 1971 and specializes in Computer-Aided De- sign.</trash>
                    </figure>
                </div>
                <div>
                    <head>Computerv m Industc~'</head>
                    <p>Aided Design facilities to develop both a modelisation of actuators and an automatic procedure to compute member inertia characteristics. Topic Nr. 2: Since no mechanical model exists for such fully flexible systems, the research work resides in defining the theoretical principles and the way they must be applied. After computer implementation , these models must be checked against the known models applicable to rigid body mechanisms , so that utilization domains may be identified for any specific method. 2. The C.A.D. Developments</p>
                </div>
                <div>
                    <head n="2.1">Purpose</head>
                    <p>Using the graphics code EUCLID developed by MATRA DATAVISION, we have created a set of utilitary subroutines enabling an engineer to define and analyse a robot in an interactive fashion (e.g. to determine from the dynamic analysis, relative to a predefined tool trajectory, forces and torques generated in members or at member con- nexions).</p>
                </div>
                <div>
                    <head n="2.2">Developments</head>
                    <p>Since different programs were involved (EUCLID for the graphical considerations, PAMTIN for the dynamic analysis of systems built of rigid bodies, and GENTRA for the geometry and kinematics problems of trajectory generation ), part of the work was concerned with interfacing these different programs so that the resulting software chain appeared easy to handle to the user. GENTRA is elaborated in a conversational manner and enables the user to define any tool trajectory composed of a succession in space of straight lines and circle portions to be run over with a specific velocity pattern 
                        <ref type="bibr" target="#b0" coords="2,178,32,546,72,20,96,8,86">[1]</ref>
                        <ref type="bibr" target="#b1" coords="2,178,32,546,72,20,96,8,86">[2]</ref>
                    </p>
                    <figure>
                        <figDesc>.</figDesc>
                    </figure>
                </div>
                <div>
                    <head n="3">The Different Mechanical Models of the Dynamic Behavior of Mechanisms Composed of Non-Rigid Elements 3.1. Problem Nr. 1: Deformation Is Located at Member Connexions</head>
                    <p>As was indicated in the Introduction, different mechanical models are available (Lagrange's equations , Newton-Euler formalism, &quot;D'Alembert's principle). Althrough their easy application mostly depends on which problem is being considered, they all lead to the following type of relationships:</p>
                    <figure>
                        <trash>A(c~t)'~t+B(~t, (~t)+B*((~t, ~I-)t)=~; (1) in which c,</trash>
                        <figDesc>:column vector of relative position variable parameters, :column vector of known efforts at member connexions, :matrix of relative acceleration quanti- ties, :column vector accounting for Coriolis acceleration. The B(~ t, i~t) column vector accounts for structural deformations. It depends only on ~t when member connexions are purely elastic, but depends on both ff~t and ~t for viscous damping dissipation at connexions. In this formulation, the major difficulty arises from not knowing any real characteristics of actuators: mass, inertia and damping values.</figDesc>
                    </figure>
                </div>
                <div>
                    <head n="3.2">Problem Nr. 2.&quot; Deformation also Induced in Structural Members</head>
                    <p>The deformed shape of structural members is then known by adding to the previous rigid body degrees of freedom ~t complementary quantities accounting for member deformations. Let Ut, V t and F t be the column vectors of this complementary d.o.f.'s and of their first and second time derivatives, velocity and acceleration. The mechanical model equations then come up to be:</p>
                    <p>
                        <formula>Ka(~,, i~t, ~b,). Ut+D(¢~,, ~,). Vt + M(~,)./', +h(tI~t)'~.lt+B(trfft, (IJt)+B*(tlJt, ~t) = Ct (2)</formula>
                    </p>
                    <p>Equation (2) includes all quantities present in equation (1) for the first problem. Moreover there appears a coupling between the rigid body system movements, parameterized by ~t and the part of the movement due to member deformations and parametrized by U, V t and Ft. Let us state here that displacements U t must have small amplitudes in order to use beam theory or shell theory equa- tions.</p>
                    <p>In order to get a simplified formulation of these equations, the last known deformed position at time (t-dt) is used as reference position instead of</p>
                </div>
                <div>
                    <head>Computers in Industry A. Barraco et al. / Dynamic Behavior of Robot-Type Structures</head>
                    <p>
                        <formula>285 lJ ~ • :/ 0 /&quot; t/l ~1~# Q Fig. 1</formula>
                    </p>
                    <p>. Closed kinematic chain definition. ~2 = 600 tr/mn 11 = 36 in; 12 =12 in; 13 = 36 in; 14 = 30 in. Cross section I x 1 in 2. E = 107 psi p = 0.101 lb/in 3. the rigid body position at time t, and then equations for time (t-dt) and t are subtracted. While introducing the displacement, velocity and acceleration increment vectors u, v and 7, we obtain the following incremental form.</p>
                    <figure>
                        <trash>#,_,,,, +,_,,,).,, + • v + M(Ot_a, ) &quot;7 = AC (3)</trash>
                    </figure>
                    <p>The solution of this equation was turned into a computer program based on the finite element technique. Spatial mechanism cases show high</p>
                    <figure>
                        <trash>' /)4/02 --@--04, s Fig. 3</trash>
                    </figure>
                    <p>. Output velocity b 4 versus input velocity ~2 diagram. complexity because of the great number of quantities involved. Plane mechanism cases are much more simple, for which we show calculation resuits in the following paragraph.</p>
                </div>
                <div>
                    <head n="3.3">Examples</head>
                    <p>The plane problems dealt with in this part were chosen so as to offer direct comparisons with results obtained by other approaches and reported in the literature. The mechanical system under study is built with three deformable members</p>
                    <figure>
                        <trash>e en P2 x 10 &quot;4 (Psi) 1.5 0 4 04, s 0.5 1 2 3 0 2 I / I I I I~ 7r / 2 /r Fig. 2</trash>
                    </figure>
                    <p>. Output angle 0 4 versus input angle 0 2 diagram.</p>
                    <p>
                        <formula>2 1 -1 -2 --3 1</formula>
                    </p>
                    <p>A.,/2 Fig. 4. Bending stress at the middle point P2 of member 2 (solution in [4]).</p>
                </div>
                <div>
                    <head>Industrial Robotics in Discrete Manufacturing</head>
                    <p>
                        <formula>Computers m lndu,~trv 4 g. 3 0 × 1 09 .~--2 m 3 -4 P2 &lt;</formula>
                    </p>
                    <note>%.~'~ /t - Mechanism 1 ',;, 7220 -/ ..... 1-2--1 --.--1 3--1 Fig. 5</note>
                    <p>. Effect of division on coupler stress.</p>
                    <figure>
                        <trash>1 Damping C = 302 M, 2 Damping C = 2 02 M, 3 Damping C = 02 M, 4 Damping C = 0.</trash>
                    </figure>
                    <p>nected at their ends by hinges. This structure is a closed kinematic chain.</p>
                    <p>For this mechanism shown in Fig. 1, resulting values are compared: -on one hand, between rigid and deformable member structures. Of particular interest are the relationships between the input angle and angular velocity and their output counterparts [3] and Figs. 2 and 3. -on the other hand, between the different formulations available that account for member deformations [4] and Figs. 4 and 5.</p>
                </div>
                <div>
                    <head>From Fig. 2</head>
                    <p>that relates the 94, a output angle variations for deformable elements to its 64. ,</p>
                    <figure>
                        <trash>en P4 x 10 4 (Psi) 5 4 3 2 1 1 2 3 Fig. 6</trash>
                        <figDesc>. Bending stress at the middle point P4 of member 3. terpart for rigid members, we can check that: ..... the time diagram for 04, , well matches the classical solution proposed in [3]</figDesc>
                    </figure>
                    <p>; -the 04, J values show oscillations about 04,, solution , the amplitude of these variations depending on both the flexibility of mechanical elements and the importance of the inertia wheel installed on the output axis. Fig. 3 shows how the output angular velocities/94, a and 04,s behave when members are deformable or rigid. Once again the 04,d values show oscillations about the 04,, variation diagram, while the amplitude of these variations is larger than that of Fig. 2</p>
                    <figure>
                        <figDesc>.</figDesc>
                    </figure>
                </div>
                <div>
                    <head n="4">Conclusions</head>
                    <p>We have shown that the requirement for CAD tools is to integrate them in a continuous software chain for conception and simulation of mecha- nisms. Concerning the different mechanical models of dynamic behavior under consideration, examples for plane mechanisms have been tested and checked against other authors' analyses. The problem is now to properly limit domains in which different types of simplifications are acceptable and thus lead to knowing what specific formulation is applicable to each particular case.</p>
                </div>
            </body>
            <back>
                <div type="acknowledgement">
                    <head>Acknowledgement</head>
                    <p>This work is supported by the &quot;Automatisme Robotique Avanc6e&quot; research project, sponsored by the Centre National de La Recherche Scien- tific.</p>
                </div>
                <div type="references">
                    <listBibl>
                        <biblStruct xml:id="b0">
                            <monogr>
                                <title level="m" type="main">Contribution h la Modblisation et it la Commande Dynamique des Robots Manipulateurs</title>
                                <author>
                                    <persName>
                                        <forename type="first">M</forename>
                                        <surname>Renaud</surname>
                                    </persName>
                                </author>
                                <imprint>
                                    <date type="published" when="1980" />
                                    <pubPlace>Montpellier</pubPlace>
                                </imprint>
                            </monogr>
                            <note>Th~se. de Doctorat d'Etat</note>
                        </biblStruct>
                        <biblStruct xml:id="b1">
                            <analytic>
                                <title level="a" type="main">Projet de fin d'&amp;udes 1982-1983</title>
                                <author>
                                    <persName>
                                        <forename type="first">Trajectoires</forename>
                                        <surname>Gbnkration De</surname>
                                    </persName>
                                </author>
                            </analytic>
                            <monogr>
                                <title level="j">D~partement STRUCTURES-ENSAM</title>
                                <imprint/>
                            </monogr>
                        </biblStruct>
                        <biblStruct xml:id="b2">
                            <monogr>
                                <title level="m" type="main">Mbthode de Conception Cinkmatique des Mbcanismes</title>
                                <author>
                                    <persName>
                                        <forename type="first">J</forename>
                                        <surname>Herv~</surname>
                                    </persName>
                                </author>
                                <imprint/>
                            </monogr>
                            <note>Centre. de Formation de rEcole Centrale des Arts et Manufactures</note>
                        </biblStruct>
                        <biblStruct xml:id="b3">
                            <monogr>
                                <title level="m" type="main">Kineto-Elastodynamic Analysis of Mechanisms by Finite Element Method. Mechanism and Machine Theory</title>
                                <author>
                                    <persName>
                                        <forename type="first">P</forename>
                                        <forename type="middle">K</forename>
                                        <surname>Nath</surname>
                                    </persName>
                                </author>
                                <author>
                                    <persName>
                                        <forename type="first">A</forename>
                                        <surname>Ghosh</surname>
                                    </persName>
                                </author>
                                <imprint>
                                    <date type="published" when="1980" />
                                </imprint>
                            </monogr>
                        </biblStruct>
                        <biblStruct xml:id="b4">
                            <monogr>
                                <title level="m" type="main">A Lumped Parameter Approach to Vibration and Stress Analysis of Elastic Systems . Transaction of ASME, Nr</title>
                                <author>
                                    <persName>
                                        <forename type="first">J</forename>
                                        <forename type="middle">P</forename>
                                        <surname>Sandier</surname>
                                    </persName>
                                </author>
                                <author>
                                    <persName>
                                        <forename type="first">G</forename>
                                        <forename type="middle">N</forename>
                                        <surname>Sandor</surname>
                                    </persName>
                                </author>
                                <imprint>
                                    <date type="published" when="1973" />
                                    <biblScope unit="page" from="95" to="549" />
                                </imprint>
                            </monogr>
                        </biblStruct>
                    </listBibl>
                </div>
            </back>
        </text>
    </TEI>

    Comme vous pouvez le voir ce sont de grands fichiers. Mon objectif est d'arriver à un fichier simplifié : titre, mots-clés, abstract, corps du texte :

    Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-model href="file:///opt/grobid-grobid-parent-0.3.9/grobid-home/schemas/rng/Grobid.rng" schematypens="http://relaxng.org/ns/structure/1.0"?>
    <TEI xmlns="http://www.tei-c.org/ns/1.0">
        <title>blabla</blabla>
        <keywords>
            <term>blabla</term>
            <term>blabla</term>
            <term>blabla</term>
        </keywords>
        <abstract>blablablablabla</abstract>
        <body>blablabla</body
    </TEI>

    Je ne sais pas ce qui est le mieux, la meilleure méthode à prendre : supprimer les balises dont je n'ai pas besoin sachant que certaine sont imbriquées dans d'autres (cf. les balises <p> dont le contenu doit rester) ou écrire entièrement le fichier xml ?

    Merci de votre aide !

  2. #2
    Responsable Perl et Outils

    Avatar de djibril
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    19 820
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 19 820
    Points : 499 184
    Points
    499 184
    Par défaut
    Bonjour,

    Il faut que tu définisses clairement tout ce que tu souhaites supprimer, modifier avant de te lancer en tenant compte des cas particuliers. Ensuite, tu utilises le module XML::Twig qui fera l'affaire.

  3. #3
    Expert éminent Avatar de CosmoKnacki
    Homme Profil pro
    Justicier interdimensionnel
    Inscrit en
    Mars 2009
    Messages
    2 858
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Charente Maritime (Poitou Charente)

    Informations professionnelles :
    Activité : Justicier interdimensionnel

    Informations forums :
    Inscription : Mars 2009
    Messages : 2 858
    Points : 6 556
    Points
    6 556
    Par défaut
    À mon avis, la méthode la plus appropriée serait d'utiliser XSLT, ça demande de l'apprentissage, mais ça me semble la méthode la plus directe pour ce que tu veux faire (voir le module XML::XSLT et les tutoriels XSLT sur le site).

    Maintenant tu peux aussi utiliser XML::libXML qui t'autorisera deux autres approches pour extraire les données, soit en construisant une représentation arborescente du document XML (que tu pourras interroger pour récupérer ce qui t'intéresse), soit en utilisant un gestionnaire d'événements (le document est parcouru élément par élément, et toi tu as défini des règles à l'avance comme: si l'élément est une balise ouvrante et que son nom est toto alors fait ci ou fait ça). Après, en ce qui concerne la construction du résultat, tu peux également utiliser ce module en créant et en peuplant chacun des éléments dont tu auras besoin, ou en composant une simple chaîne de caractères.
    Brachygobius xanthozonus
    Ctenobrycon Gymnocorymbus

  4. #4
    Nouveau Candidat au Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Mars 2016
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2016
    Messages : 4
    Points : 1
    Points
    1
    Par défaut
    Citation Envoyé par djibril Voir le message
    Bonjour,

    Il faut que tu définisses clairement tout ce que tu souhaites supprimer, modifier avant de te lancer en tenant compte des cas particuliers.
    Disons qu'il y a des balises que je souhaiterais totalement supprimer comme <fileDesc> et d'autres que je souhaiterais supprimer tout en gardant le contenu comme <p>. Tout le texte ne serait en fait contenu que dans <body> sans aucune balise imbriquée (si ce n'est peut-être celle des titres de parties mais ça je ne sais pas encore ce que je vais faire).
    Du coup tu me conseilles de supprimer plutôt que de créer un tout nouveau fichier XML?

    Citation Envoyé par djibril Voir le message
    Ensuite, tu utilises le module XML::Twig qui fera l'affaire.
    Idéalement oui je voudrais utiliser le module XML::Twig.

  5. #5
    Nouveau Candidat au Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Mars 2016
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2016
    Messages : 4
    Points : 1
    Points
    1
    Par défaut
    Citation Envoyé par CosmoKnacki Voir le message
    À mon avis, la méthode la plus appropriée serait d'utiliser XSLT, ça demande de l'apprentissage, mais ça me semble la méthode la plus directe pour ce que tu veux faire (voir le module XML::XSLT et les tutoriels XSLT sur le site).

    Maintenant tu peux aussi utiliser XML::libXML qui t'autorisera deux autres approches pour extraire les données, soit en construisant une représentation arborescente du document XML (que tu pourras interroger pour récupérer ce qui t'intéresse), soit en utilisant un gestionnaire d'événements (le document est parcouru élément par élément, et toi tu as défini des règles à l'avance comme: si l'élément est une balise ouvrante et que son nom est toto alors fait ci ou fait ça). Après, en ce qui concerne la construction du résultat, tu peux également utiliser ce module en créant et en peuplant chacun des éléments dont tu auras besoin, ou en composant une simple chaîne de caractères.
    Merci pour tes conseils, je vais me pencher dessus.

  6. #6
    Responsable Perl et Outils

    Avatar de djibril
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    19 820
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 19 820
    Points : 499 184
    Points
    499 184
    Par défaut
    Un programme XML::Twig est vite fait. Apprendre le XSLT pour cela je trouve que c'est se compliquer la vie.

  7. #7
    Expert éminent Avatar de CosmoKnacki
    Homme Profil pro
    Justicier interdimensionnel
    Inscrit en
    Mars 2009
    Messages
    2 858
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Charente Maritime (Poitou Charente)

    Informations professionnelles :
    Activité : Justicier interdimensionnel

    Informations forums :
    Inscription : Mars 2009
    Messages : 2 858
    Points : 6 556
    Points
    6 556
    Par défaut
    Peut-être, mais il faut bien y passer et même si ça n'est pas forcément très intuitif au début, cet apprentissage est payant au final, parce qu'on a compris beaucoup de choses et qu'on dispose d'un outil utilisable dans n'importe quel langage.
    Brachygobius xanthozonus
    Ctenobrycon Gymnocorymbus

  8. #8
    Nouveau Candidat au Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Mars 2016
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2016
    Messages : 4
    Points : 1
    Points
    1
    Par défaut
    Bonjour,

    Ça faisait un petit bout de temps mais j'ai réussi à faire quelque chose. Bon ce n'est pas fini parce qu'il faut encore que je supprime des éléments qui ne me sont pas utiles mais j'ai au moins pu sélectionner ce dont j'avais besoin (j'ai mis en pièce-jointe le fichier xml que j'ai utilisé pour le traitement) :

    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
    #!/usr/bin/perl
     
    use strict ;
    use warnings ;
    use utf8 ;
    use XML::Twig ;
    use Data::Dumper ;
     
    binmode (STDOUT, ":utf8") ;
    ActiverAccentDOS() ; # appel de la fonction d'activation des accents
     
    my $file = "Accounting_for_Member_Deformations_in_the_Determination_of_the_Dynamic_Behavior_of_Robot-Type_Structures.xml" ;
     
    my $twig = XML::Twig->new (
      twig_roots => {
        'teiHeader/fileDesc/titleStmt/title' => \&print_title ,
        'teiHeader/profileDesc/textClass/keywords' => \&print_keywords ,
        'teiHeader/profileDesc/abstract/p' => \&print_abstract ,
        'teiHeader/profileDesc/abstract/p' => sub { $_->set_tag ('abstract') } , #changement de nom de la balise 'p' dans 'abstract'
        'text/body' => \&print_introduction
        # 'text/body' => \&print_body
      }
    ) ;
     
    ############# TITLE #############
    sub print_title {
      my ($twig, $elt) = @_ ;
      $elt->del_att('level', 'type') ; #supprime les attributs
      my $title = $elt->child(0)->text ;
    }
    #################################
     
    ############# KEYWORDS ##########
    sub print_keywords {
      my ($twig, $elt) = @_ ;
      my @keywords = $elt->first_child('term')-> text ;
    }
    #################################
     
    ############# ABSTRACT ##########
    sub print_abstract {
      my ($twig, $elt) = @_ ;
      my $abstract = $elt->child() -> text ;
      # print "\n<abstract>$abstract</abstract>" ;
    }
    #################################
     
    ############# INTRODUCTION ######
    sub print_introduction {
      my ($twig, $elt) = @_ ;
      my $introduction = $elt->child() -> text ;
    }
    #################################
     
     
    # sub print_body {
    #   my ($twig, $elt) = @_;
    #   my $body = $elt->first_child('div') -> text ;
    # }
     
    $twig->parsefile($file) ;
    $twig->set_pretty_print('indented');
    $twig->print_to_file("out.xml");
     
    ############# Verifie que le fichier a bien été créé #############
    if (-e "out.xml") {
      print "Fichier créé\n" ;
    }
    ##################################################################
     
     
    ############# ACCENT ############
    sub ActiverAccentDOS {
      my ($codepage) = ( `chcp` =~ m/:\s+(\d+)/ );
      foreach my $h ( \*STDOUT, \*STDERR, \*STDIN ) {
        binmode $h, ":encoding(cp$codepage)";
      }
    }
    ##################################

Discussions similaires

  1. [Débutant] Exécution d'un fichier MATLAB à partir d'un autre fichier
    Par abdouccu dans le forum MATLAB
    Réponses: 2
    Dernier message: 07/06/2012, 20h42
  2. [DOM] Reconstruire un fichier XML à partir d'un autre fichier XML
    Par Jonvols dans le forum Format d'échange (XML, JSON...)
    Réponses: 12
    Dernier message: 13/11/2010, 01h49
  3. Réponses: 5
    Dernier message: 23/03/2009, 16h36
  4. générer un fichier xml à partir d'un gros fichier plat
    Par ybennani dans le forum Format d'échange (XML, JSON...)
    Réponses: 7
    Dernier message: 16/05/2007, 10h47
  5. [FPDF] Créer un fichier PDF à partir d'un autre fichier PDF
    Par axel-erator dans le forum Bibliothèques et frameworks
    Réponses: 5
    Dernier message: 18/06/2006, 23h29

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