Thread Zeiger in einer Datei, um da die Zeilen aus der 2. Datei zu schreiben
(6 answers)
Opened by alla at 2010-05-26 18:36
also wenn ich dich richtig verstanden habe, gibt es n blöcke in der datei 1 und n find-spot-elemente in der xml-datei.
Code: (dl
)
1 <?xml version="1.0" encoding="utf-8"?> 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 26 27 28 29 30 31 use strict; use warnings; use XML::LibXML; my $parser = XML::LibXML->new(); my $doc = $parser->parse_file("xml.xml"); my @nodes = $doc->findnodes('/items/find-spot'); my $i = 0; my @blocks = do { local $/ = "\n______________\n"; <DATA> }; for my $node (@nodes) { my $block = $blocks[$i]; my ($header, @lines) = split /\n/, $block; pop @lines; for my $line (@lines) { my $child = $node->addNewChild( "", "environment" ); $child->appendText("$line"); } $i++; } my $docstring = $doc->toString(); print "Neues XML: $docstring\n"; __DATA__ Block 1: perl1 perl2 perl3 ______________ Block 2: bla etc. ______________ Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. -- Damian Conway in "Perl Best Practices"
lesen: ![]() ![]() |