Précédent   Forum du club des développeurs et IT Pro > Autres langages > Perl > Modules
Modules Toutes vos questions sur l'utilisation, l'installation, la création de modules Perl sous Windows/Linux/Unix/MacOS. Avant de poster, veuillez consulter les FAQs perl, les cours Perl et les sources Perl.
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 21/05/2012, 15h35   #1
wboudji
Invité de passage
 
Homme
Développeur en systèmes embarqués
Inscription : 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 : 0
Points : 0
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
wboudji est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/05/2012, 19h54   #2
Lolo78
Membre Expert
 
Homme Laurent R.
Conseil - Consultant en systèmes d'information
Inscription : mai 2012
Messages : 567
Détails du profil
Informations personnelles :
Nom : Homme Laurent R.
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 : 567
Points : 1 117
Points : 1 117
Pourrais-tu donner quelques lignes du fichier XML résultat que tu souhaites obtenir à partir de ces données?
Lolo78 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 22/05/2012, 09h41   #3
Philou67430
Expert Confirmé
 
Inscription : avril 2009
Messages : 2 633
Détails du profil
Informations personnelles :
Âge : 47

Informations forums :
Inscription : avril 2009
Messages : 2 633
Points : 3 079
Points : 3 079
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é
Using strict and warnings is good for you.
Philou67430 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 23/05/2012, 10h46   #4
wboudji
Invité de passage
 
Homme
Développeur en systèmes embarqués
Inscription : 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 : 0
Points : 0
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
Type de fichier : txt XML_fichier_resultats.txt (10,4 Ko, 10 affichages)
wboudji est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 29/05/2012, 17h55   #5
sth56
Membre à l'essai
 
Inscription : mars 2009
Messages : 42
Détails du profil
Informations forums :
Inscription : mars 2009
Messages : 42
Points : 24
Points : 24
bonjour,

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

Code :
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();
sth56 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 15h52.


 
 
 
 
Partenaires

Hébergement Web