Maxim has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,
I have install th latest version of XML::LibXML in ActiveState. When I try to do that:
use XML::LibXML; use strict; my $file = (<DATA Or filename>); my $d = XML::LibXML->new->parse_string(join "", $file); for my $dead ($d->findnodes(q{/opt/node[val = "2"]})) { $dead->unbindNode; } print $d->toString; Data____ <?xml version="1.0"?> <opt> <node> <val>1</val> </node> <node> <val>2</val> </node> <node> <val>3</val> </node> </opt>

I got this error message.
:1: parser error : Start tag expected, '<' not found c:\max.xml ^ at C:\Program Files\Apache Group\Apache2\cgi-bin\legas\delsub.pl line 8

I don't know what's wrong.
Thanks in advance for your help.

Maxim

Replies are listed 'Best First'.
Re: Start tag expected
by ikegami (Patriarch) on Oct 10, 2004 at 06:06 UTC
    You're just reading in one line. Try:
    my @file = <DATA>; my $d = XML::LibXML->new->parse_string(join "", @file);

    or better yet

    my $file = do { local $/; <DATA> }; my $d = XML::LibXML->new->parse_string($file);

    Also, Data____ should be __DATA__

Re: Start tag expected
by chromatic (Archbishop) on Oct 10, 2004 at 06:09 UTC

    If <DATA Or filename> is pseudo-code, then your error is that Data____ should be __DATA__. Once you fix that, things look fine.

    By the way, the join is superfluous; joining a one-element list (or a scalar in list context) gives you the scalar back.

    Update: Things look fine in the sense that the code will compile, not that reading from DATA in scalar context will read the whole XML file. I missed that in my first answer. You'll need to slurp the entire file somehow.

Re: Start tag expected
by Maxim (Sexton) on Oct 10, 2004 at 06:40 UTC
    Hey,
    I found the mistake, I made because I didn't read enough the documentation.
    Here the answer:
    my $d = XML::LibXML->new->parse_file($file);

    Thanks to helped me
    Maxim
Re: Start tag expected
by pg (Canon) on Oct 10, 2004 at 06:51 UTC

    use warnings;

    With warnings turned on, perl will tell you there are syntax errors.

    Here is a stripped version of your code:

    use strict; use warnings; my $file = (<DATA>); Data___ <?xml version="1.0"?> <opt> <node> <val>1</val> </node> <node> <val>2</val> </node> <node> <val>3</val> </node> </opt>

    Here is the warings:

    Number found where operator expected at c.pl line 12, near "<val>1" (Missing operator before 1?) Bareword found where operator expected at c.pl line 13, near "</node" (Might be a runaway multi-line // string starting on line 12) (Missing operator before node?) Bareword found where operator expected at c.pl line 16, near "</node" (Might be a runaway multi-line // string starting on line 15) (Missing operator before node?) Bareword found where operator expected at c.pl line 19, near "</node" (Might be a runaway multi-line // string starting on line 18) (Missing operator before node?) syntax error at c.pl line 8, near "?xml version="1.0"?>" Execution of c.pl aborted due to compilation errors.

    use __DATA__, then the warnings go away.