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
| procedure TForm1.Button1Click(Sender: TObject);
var
Node : IXMLNode;
I : Integer;
Titre : IXMLNode;
Section : IXMLNode;
Ligne : IXMLNode;
List : TStringList;
Accord : Boolean;
Super : Boolean;
TiTemp : string;
DateAcc : string;
DateSup : string;
DateAcD : array of TDate;
Fichier : TStringList;
begin
XMLDocument1.LoadFromFile(ExtractFilePath(Application.ExeName)+'Fichier.xml');
Node := XMLDocument1.ChildNodes.Nodes['XML'];
Titre := Node.ChildNodes.Nodes['Titre'];
Fichier := TStringList.Create;
try
while Titre <> nil do
begin
if Titre.GetAttributeNS('intitulé','') <> '' then
TiTemp := Titre.GetAttributeNS('intitulé','')
else
Fichier.Add('Vide pas d''intitulé;;;;VIDE');
if Titre.HasChildNodes then
begin
Accord := False;
Super := False;
DateAcc := '';
DateSup := '';
Section := Titre.ChildNodes.Nodes['Section'];
while Section <> nil do
begin
if Section.HasChildNodes then
begin
Ligne := Section.ChildNodes.Nodes['Lignes'].ChildNodes.Nodes['Ligne'];
while Ligne <> nil do
begin
List := TStringList.Create;
List.Delimiter := ';';
List.DelimitedText := Ligne.NodeValue;
try
for I := 0 to List.Count - 1 do
begin
if I = 0 then
begin
if List[I]='accord' then
begin
Accord := True;
DateAcc := List[2];
SetLength(DateAcD,Length(DateAcD)+1);
DateAcD[Length(DateAcD)-1] := StrTodate(List[2]);
end;
if List[I]='SUPER' then
begin
Super := True;
DateSup := List[2];
end;
end;
end;
Ligne := Ligne.NextSibling;
finally
List.Free;
end;
end;
if Titre.GetAttributeNS('intitulé','') <> '' then
begin
if not Accord and not Super then
Fichier.Add(TiTemp+Section.GetAttributeNS('nom','')+';;VIDE');
{if Accord and not Super then
Fichier.Add(TiTemp+Section.GetAttributeNS('nom','')+';'+DateAcc+';ACCORD');
if Accord and Super then
Fichier.Add(TiTemp+Section.GetAttributeNS('nom','')+DateSup+';'+DateAcc+';SUPER ACCORD');}
if Accord and not Super then
for I := 0 to Length(DateAcD)-1 do
Fichier.Add(TiTemp+Section.GetAttributeNS('nom','')+';'+DateToStr(DateAcD[I])+';ACCORD');
if not Accord and Super then
Fichier.Add(TiTemp+Section.GetAttributeNS('nom','')+DateSup+';;SUPER');
if Accord and Super then
for I := 0 to Length(DateAcD)-1 do
Fichier.Add(TiTemp+Section.GetAttributeNS('nom','')+DateSup+';'+DateToStr(DateAcD[I])+';SUPER ACCORD');
SetLength(DateAcD,0);
end;
Section := Section.NextSibling;
end
else
Fichier.Add(TiTemp+'Section vide;;;VIDE');
end;
end
else
if Titre.GetAttributeNS('intitulé','') <> '' then
Fichier.Add(TiTemp+'Pas de section;;;VIDE');
Titre := Titre.NextSibling;
end;
Fichier.SaveToFile(ExtractFilePath(Application.ExeName)+'Resultat.csv');
finally
Fichier.Free;
FreeMemory(DateAcD);
end;
end; |
Partager