in reply to Stripping off the first line of file help!

<? blah blah ?> is a standard XML header format. So it's the XML::XPATH module that is at fault.

But the module will accept a scalar instead of a file of XML to process. So you could slurp the file into a variable and then: Because the header appears only once, a workaround substitution like:

s/\<\?.*\?\>//;
should be sufficient.

I would tend not to remove the first line, because carriage control is just noise to XML and shouldn't be part of any parsing algorithm - even a simple parsing helper as in this case.

One world, one people

Replies are listed 'Best First'.
Re^2: Stripping off the first line of file help!
by Anonymous Monk on Mar 03, 2011 at 16:11 UTC
    OK, I can do this but how would I use XML::XPATH after slurping the file into a variable? Here is my situation: Its been treated as text, I rather treat the file like XML for validation. Any suggestions?
    my @memberstocheck = ('12345', '88766', '887766', '009888', '111233', +'99877'); # Check XML file. my @xml = $zip->membersMatching( '.*\.XML' ); foreach (@xml) { # Slurp file my $contents = $_->contents(); open my $contents_fh, '<', \$contents or die "Can't open scalar filehandle: $!"; my $first_line = <$contents_fh>; while (<$contents_fh>) { chomp; if(/<accnumber>(.*?)<\/accnumber>/gi) { my $acc = $1; foreach (@memberstocheck) { if (/^($acc)/g) { print "$acc - ".$_."\n"; } } } } }