summaryrefslogtreecommitdiffstats
path: root/kresources/groupwise/soap/extractxml.pl
blob: ecab50861e1ffdf9872bd5826f98fb7c7a80ce35 (plain)
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
#!/usr/bin/perl

if ( @ARGV != 1 ) {
  print STDERR "Usage: extractxml.pl <filename>\n";
  exit 1;
}

$in = $ARGV[ 0 ];

print "In: $in\n";

if ( !open IN, $in ) {
  print STDERR "Unable to open file '$in'.\n";
  exit 1;
}

$count = 1;

while ( <IN> ) {
  if ( $xml ) {
    if ( $_ =~ /(.*\<\/SOAP-ENV:Envelope\>)/ ) {
      printXml( $xml . $1 );
      $xml = "";
    } else {
      $xml .= $_;
    }
  } elsif ( $_ =~ /^(\<\?xml.*\?>)(.*)$/ ) {
    $xml = $1 . $2;

    if ( $xml =~ /(.*\<\/SOAP-ENV:Envelope\>)/ ) { 
      printXml( $1 );
      $xml = "";
      
    }
  }
}

sub printXml()
{
  $xml = shift;

  $xml =~ s/\n//g;
  $xml =~ s/\r//g;

  $out = "$in.$count.xml";

  print "Out: $out\n";

  if ( !open OUT, ">$out" ) {
    print STDERR "Unable to open file '$out'.\n";
  } else {
    print OUT $xml;
    close OUT;
  }

  $count += 1;
}