
Stefanik
User
Jan 15, 2013, 5:53 AM
Post #11 of 15
(6191 views)
|
I write a code to perform the indent xml tag: my $fin="InputXML.log"; my $fout="OutputXML.log"; my $countxml=0; my $qx="x";open (NSOFILE, "<", $fin) or die "No file!"; open (NOUTFILE, ">", $fout) or die "No file!";while ($qx = <NSOFILE>){ print "inizio: "."$countxml\n"; if ($qx =~ (/^<[^\?|\/].*?>/m)){ ###Check StartTag $countxml++; my $cind = $countxml; while ($cind != 0) { $qx =~ s/</\t </g; $cind--; } } elsif ($qx =~ (/<\//m)){ ###Check EndTag my $cind = $countxml; while ($cind != 0) { $qx =~ s/</\t </g; $cind--; } $countxml--; } elsif ($qx =~ (/>\n.*\n<\//m)) ###check Value between tag my $cind = $countxml; while ($cind != 0) { $qx =~ s/(>\n.*\n<\/)/(>\n\t.*\n<\)/g; $cind--; } } } close (NSOFILE); close (NOUTFILE); The Input file contains something like this: DELETE: TESTSUB: NUM,458: PARAMETERS,other; RESP: 0; <?xmlversion='1.0'encoding='ISO-8859-1'standalone='no'?> <Request> <operation> DeleteSubscriber </operation> <subscriberNumbertype="string"> 458 </subscriberNumber> <originNodeTypetype="string"> ADM </originNodeType> <originHostNametype="string"> lh </originHostName> <originTransactionIDtype="string"> 4568768597657 </originTransactionID> <Lev1> <mystring> here </mystring> </Lev1> <originTimeStamptype="dateTime.iso8601"> 20130109T11:18:22+0100 </originTimeStamp> </barring> </Request> Output I produce is this: DELETE: TESTSUB: NUM,458: PARAMETERS,other; RESP: 0; <?xmlversion='1.0'encoding='ISO-8859-1'standalone='no'?> <Request> <operation> DeleteSubscriber </operation> <subscriberNumbertype="string"> 458 </subscriberNumber> <originNodeTypetype="string"> ADM </originNodeType> <originHostNametype="string"> lh </originHostName> <originTransactionIDtype="string"> 4568768597657 </originTransactionID> <Lev1> <mystring> here </mystring> </Lev1> <originTimeStamptype="dateTime.iso8601"> 20130109T11:18:22+0100 </originTimeStamp> </Request>
|