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

Modules Perl Discussion :

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


Sujet :

Modules Perl

  1. #1
    Candidat au Club
    Homme Profil pro
    Développeur en systèmes embarqués
    Inscrit en
    Mai 2012
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur en systèmes embarqués
    Secteur : Industrie

    Informations forums :
    Inscription : Mai 2012
    Messages : 3
    Points : 3
    Points
    3
    Par défaut Création fichier XML à partir d'un fichier texte
    Bonjour,

    Tout nouveau dans la programmation PERL, je souhaite creer un fichier XML comme entrée pour l'outil design Enterprise Architect à partir d'un fichier texte contenant des infos hierarchisées comme suit : 1, 1.1, 1.2 etc ...

    1 Chapter PURPOSE AND SCOPE OF THIS DOCUMENT (2420773) SectionID_3A13384E_8231_03d4_F7DC_7ECE6F383950

    1.3 section Filter algorithm (2407920) SectionID_F9561D84_6EBC_541f_D920_36E3994FA2E0

    1.4 section Shutdown Prevention (2587622) SectionID_C36D589D_5FFE_c735_AFE1_72125316EEB0

    1.5 section Nomenclature (2407843) SectionID_B74FDCAF_C84C_2f23_5391_97A2D2B25702

    1.5.2 section Functional Description (2471223) SectionID_E33198DC_8948_9cba_7C3B_5D6084EC5AE0

    1.5.2.2 section Input Signals (2471225) SectionID_397FDA6E_5C89_40aa_FC6D_FB9892BF2A9B

    1.5.2.3 section Output Signals (2471226) SectionID_94F099C9_6CAF_b091_69C8_692F0B596FF7

    1.5.2.4 section Parameters (2471209) SectionID_F2E4833C_856D_2a41_332A_9E1E6CA3108C

    1.5.2.5 section Requirement 1 (2471216) SectionID_B6F1237A_5CD8_0a4f_970B_30139F003291

    2 Chapter Context (2636865) SectionID_BAA32D7A_DFAD_df85_1ACF_E75EE6BCCBB1

    2.1 section ASIL Level (2636867) SectionID_6E341872_E187_132e_E884_373E568CCBB8

    3 Chapter Name as Black Box (2407873) SectionID_37B79FED_A551_2aee_F18C_BBA600798308

    3.3 section Loop Definition (2407849) SectionID_ED9CEECE_A0EA_7afb_BEAB_229B7577656D

    3.4 section Black Box Signal Interface (2407882) SectionID_2FF4CA9B_5A2B_19d5_24E3_F3D11E18CFBA

    3.4.2 section Incomming Signals (2407899) SectionID_CA437180_C3EB_0dc8_DF1C_0D7C5DBC811E

    3.4.3 section Outgoing Signals (2407887) SectionID_A0223F72_5A25_d64b_2C75_90D39F1B792E

    3.4.4 section Use Case Time Sequences (2443627) SectionID_FE4BBFEE_B36B_7ad0_7B62_4EA45CEA30EF

    etc ....

    Il semblerait que l'on puisse utiliser la librairie XML:Writer and surement implementer une fonction recursive pour scruter le fichier texte et extraire la hierarchie pour la transposer dans le fichier XML.

    Merci pour votre aide. C'est assez urgent ! Slts

  2. #2
    Rédacteur/Modérateur

    Avatar de Lolo78
    Homme Profil pro
    Conseil - Consultant en systèmes d'information
    Inscrit en
    Mai 2012
    Messages
    3 612
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Conseil - Consultant en systèmes d'information
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mai 2012
    Messages : 3 612
    Points : 12 469
    Points
    12 469
    Billets dans le blog
    1
    Par défaut
    Pourrais-tu donner quelques lignes du fichier XML résultat que tu souhaites obtenir à partir de ces données?

  3. #3
    Expert confirmé

    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2009
    Messages
    3 577
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Avril 2009
    Messages : 3 577
    Points : 5 753
    Points
    5 753
    Par défaut
    Autre point, dans ton exemple, on note qu'il n'y a pas de paragraphe 1.1, 1.2, 1.5.1, 1.5.2.1, 3.1, 3.2, 3.4.1

    Faut-il les introduire malgré tout dans le format XML attendu ?
    Plus j'apprends, et plus je mesure mon ignorance (philou67430)
    Toute technologie suffisamment avancée est indiscernable d'un script Perl (Llama book)
    Partagez vos problèmes pour que l'on partage ensemble nos solutions : je ne réponds pas aux questions techniques par message privé
    Si c'est utile, say

  4. #4
    Candidat au Club
    Homme Profil pro
    Développeur en systèmes embarqués
    Inscrit en
    Mai 2012
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur en systèmes embarqués
    Secteur : Industrie

    Informations forums :
    Inscription : Mai 2012
    Messages : 3
    Points : 3
    Points
    3
    Par défaut
    Bonjour,

    J'ai attaché en piece jointe un fichier txt pour avoir un exemple du fichier XML que je souhaite obtenir. J'ai modifié volontairement quelques champs pour des raisons de confidentialité.

    Merci pour ton aide.
    Cordialement
    Fichiers attachés Fichiers attachés

  5. #5
    Membre du Club
    Profil pro
    Inscrit en
    Mars 2009
    Messages
    43
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2009
    Messages : 43
    Points : 42
    Points
    42
    Par défaut
    bonjour,

    Un début de script qui te permettra de répondre à ton besoin en utilisant le module 'XML::Writer'.

    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
    #!/usr/bin/perl
    use XML::Writer;
    use IO::File;
     
    my $output = new IO::File(">output.xml");
     
    my $writer = new XML::Writer( 
        OUTPUT      => $output,
        DATA_INDENT => 3,             # indentation, trois espaces
        DATA_MODE   => 1,             # changement ligne.
        ENCODING    => 'utf-8',
    );
     
     
    my @tab = ("1 1 Chapter PURPOSE AND SCOPE OF THIS DOCUMENT (2420773) SectionID_3A13384E_8231_03d4_F7DC_7ECE6F383950",
    			"1.3 1.3 section Filter algorithm (2407920) SectionID_F9561D84_6EBC_541f_D920_36E3994FA2E0",
    			"1.4.3 1.4.3 section Shutdown Prevention (2587622) SectionID_C36D589D_5FFE_c735_AFE1_72125316EEB0",
    			"2 2 Chapter Context (2636865) SectionID_BAA32D7A_DFAD_df85_1ACF_E75EE6BCCBB1",
    			"2.1 2.1 section ASIL Level (2636867) SectionID_6E341872_E187_132e_E884_373E568CCBB8",
    			"3 3 Chapter Name as Black Box (2407873) SectionID_37B79FED_A551_2aee_F18C_BBA600798308");
     
    my $xmiId;
    my $name;
    my $bFinTag = 0;
    my $nbTagOuvert = 1;
    my @tabNumParagraphe;
    my $numParagraphe = '';
    my $numParagrapheOld = '';
     
    $writer->xmlDecl("UTF-8");
     
     
    $writer->startTag("xmi:XMI",
    				"xmi:version" => "2.1",
    				"xmlns:uml" => "http://schema.omg.org/spec/UML/2.1",
    				"xmlns:xmi" => "http://schema.omg.org/spec/XMI/2.1",
    				"xmlns:thecustomprofile" => "http://www.sparxsystems.com/profiles/thecustomprofile/1.0");
     
    $writer->emptyTag("xmi:Documentation",
    				"exporter" => "Enterprise Architect",
    				"exporterVersion" => "6.5");
     
     
    $writer->startTag("uml:Model",
    				"xmi:type" => "uml:Model",
    				"name" => "EA_Model",
    				"visibility" => "public");
     
    foreach(@tab){
    	$ligne = $_;
     
    	if($ligne =~ /(\d+(\.\d+)*)\s(.*)\sSectionID_(.*)/){
    		$xmiId = $3;
    		$name = $4;
    		@tabNumParagraphe = split('\.',$1);
     
    		$numParagraphe = $tabNumParagraphe[0];
     
    		if(($numParagrapheOld ne '') and ($numParagraphe > $numParagrapheOld)){
    			$bFinTag =1;
    		}
     
    		$numParagrapheOld = $numParagraphe;
     
    	}
     
    	if($bFinTag){
    		$writer->endTag("packagedElement") ;
    		$nbTagOuvert--;	
     
    		for($i=1;$i<$nbTagOuvert;$i++){
    			$writer->endTag("packagedElement");
    			$nbTagOuvert--;	
    		}	
    		$bFinTag = 0;	
    	}		
     
    	$writer->startTag( "packagedElement", 
    					"xmi:type" => "uml:Package", 
    					"xmi:id" => "$xmiId", 
    					"name" => "$name" );
     
    	$nbTagOuvert++;
     
    }
     
    for($i=1;$i<$nbTagOuvert;$i++){
    	$writer->endTag("packagedElement");
    }	
     
    $writer->endTag("uml:Model");
    $writer->endTag("xmi:XMI");
    $writer->end();
    $output->close();

Discussions similaires

  1. Generer un fichier xml à partir d'un fichier text
    Par maissaab dans le forum XML/XSL et SOAP
    Réponses: 6
    Dernier message: 05/04/2011, 10h18
  2. Création tableau Excel à partir d'un fichier XML
    Par promoshop dans le forum Excel
    Réponses: 1
    Dernier message: 25/01/2011, 17h12
  3. [XL-2003] Création fichier XML à partir d'un fichier Excel
    Par tiboots dans le forum Macros et VBA Excel
    Réponses: 3
    Dernier message: 17/08/2009, 23h25
  4. création de tables à partir d'un fichier XML
    Par magic charly dans le forum Oracle
    Réponses: 2
    Dernier message: 03/04/2006, 14h39
  5. Générer un exemple de fichier xml à partir d'un fichier
    Par leuqui dans le forum XML/XSL et SOAP
    Réponses: 3
    Dernier message: 01/07/2005, 10h25

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