Thread Attributname sprengt Formatierung (12 answers)
Opened by Commu at 2016-08-23 13:44

Linuxer
 2016-08-23 18:56
#185280 #185280
User since
2006-01-27
3869 Artikel
HausmeisterIn

user image
Mit folgenden Code liegt das Resultat doch schon mal recht nahe am Original (nachdem ich die ungeschlossenen Tags auch mal wieder geschlossen habe, um etwas halbwegs valides zu haben):

Update 21:00: Code(s) angepasst, damit die Attribute des Tag erhalten bleiben, das nun Content "Anlegen" erhält.

Code (perl): (dl )
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
#!/usr/bin/perl

use strict;
use warnings;

use XML::Simple;

my $in_file = "in.xml";
my $xml_file = 'out.xml';

my $xml = XMLin(
    $in_file,
    KeepRoot => 1,
    ForceArray => 1,
);

# added ->{content}, so now attributes are preserved and stay
$xml->{importrecord}->[0]->{aktionen}->[0]->{transaktion}->[0]->{aktion}->[0]->{parameter}->[0]->{attribut}->[0]->{content} = 'Anlegen';

XMLout(
    $xml,
    KeepRoot => 1,
    NoAttr => 0,
    OutputFile => $xml_file,
);


Resultat:

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<importrecord>
<aktionen>
<transaktion>
<aktion>
<parameter>
<attribut attributname="aktion">Anlegen</attribut>
<attribut attributname="bereich" />
<attribut attributname="dokumenttyp" />
<attribut attributname="voname" />
<attribut attributname="gz" />
<attribut attributname="betreff" />
</parameter>
</aktion>
</transaktion>
</aktionen>
<dateiname>24845_2874846.fmd</dateiname>
</importrecord>


Die fehlende XML-Deklaration und das verschwundene attributname="aktion" müssen dann noch eingearbeitet werden...
Last edited: 2016-08-23 21:02:30 +0200 (CEST)
meine Beiträge: I.d.R. alle Angaben ohne Gewähr und auf Linux abgestimmt!
Die Sprache heisst Perl, nicht PERL. - Bitte Crossposts als solche kenntlich machen!

View full thread Attributname sprengt Formatierung