I'm trying to add copyright information to the top of XML files. However, it needs to go after the prologue:
<?xml version="1.0"?>
<!DOCTYPE ...>
My problem is that some XML Documents have the <!DOCTYPE...> tag spread out over many lines and I need to add the copyright information after the whole tag. With the following regular expression, it only matches the first line of the <!DOCTYPE...> tag. Any help would be appriciated. Thanks.
if($XML)
{
[INDENT] $holdTerminator = $/;
undef $/;
$buf = <DAT> or die "Can't read into variable";
$/ = $holdTerminator;
if($buf =~ m/(<\?xml version="\d\.\d".*\?>[.\s\n]*(<!DOCTYPE.*>?)?)/i)
{[/INDENT]
[INDENT] [INDENT]print "XML $1";
$version=$1;
$buf =~ s/<\?xml version="\d\.\d".*\?>[.\s\n]*(<!DOCTYPE.*>?)?/$version \n\n $start_comment $copyright $end_comment/i;
seek(DAT, 0, 0);
print DAT $buf;[/INDENT] [/INDENT]
[INDENT]}[/INDENT]
}