Lev Lvovsky wrote:
> On Mar 15, 2007, at 11:01 AM, Garrett, Philip (MAN-Corporate) wrote:
>
>> Not necessarily. It's possible (and likely) to have a large xml file
>> with no line breaks. You wouldn't want to load the entire thing into
>> memory to parse it.
>
> Makes sense - good thing to remember too, I've prettified all of my
> XML (line breaks and all), so it's likely that later on down the road
> printing out the line would make output unreadable - I suppose the
> colmumn number could allow for printing out snippets from that single
> line however.
I've found this bit of code useful to report the actual element an error
occurred in or near. It isn't foolproof, but if you're just trying to
give someone an idea of where to look, it comes in handy. I wouldn't
recommend using it if your XML files might be large for the same reason
were discussed earlier.
my $filename = $err->getSystemId();
my $line = $err->getLineNumber();
my $column = $err->getColumnNumber();
my $message = $err->getMessage();
open(my $FILE,"<$filename");
while (<$FILE>) {
next unless $. == $line;
# truncate past column
substr($_,$column) = '' if length($_) >= $column;
$_ = reverse($_);
my ($tag) = ($_ =~ />\/? ?([\w:-]+)/);
if ($tag) {
$tag = reverse($tag);
$message .= " in element '$tag'";
}
last;
}
close($file);
# ... Report error ...
- Philip
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]