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

Hey Everyone,

I'm trying to parse a xml file that has just one line!!!!...this is a 64kb xml file that is a one liner.

Everytime I try to parse it and print out certain items, I always receive this error when using XML::RSS

no element found at line 1, column 0, byte 0 at C:/Perl/site/lib/XML/Parser.pm line 187 I don't know whats wrong, when I place it with a different XML that seems more formatted and uses new lines for each items/elements, then my code works.

I narrowed this problem of mine due to the xml file that I'm trying to parse is different from others.

What other modules I can use besides XML::RSS that will parse this xml file of mine?

Thanks

Replies are listed 'Best First'.
Re: Parsing XML
by Zaxo (Archbishop) on May 29, 2005 at 08:19 UTC

    Try XML::Parser. The "no element . . ." error may indicate malformed xml, but it may just be that it doesn't act like RSS. The position suggests that you may lack a root element.

    After Compline,
    Zaxo

      Thanks for the quick replies

      Nope, never tried validating the xml.

      The thing is, I think I'm trying to use XML::RSS and parsing the file as if it was a RSS xml feed file.

      The beginning part of the first line is <?xml version="1.0"?>

      Basically I want to read and parse certain items from the xml file, so I guess I will try using XML::Parser.
      From my post above, the error says its coming from line 187 from the XML::Parser module file. Its maybe because I'm using it with XML::RSS and that my xml file is not a rss rile, but instead a xml 1.0 file.

      Thanks
Re: Parsing XML
by mirod (Canon) on May 29, 2005 at 09:31 UTC

    The 'no element found ...' message actually comes from XML::Parser, which is used by XML::RSS. Often you get that message if you parse a filename (you wanted to parse the file but you parsed the string because you used the parse method instead of the parsefile method).

    If this is not the problem, you should parse the XML with xmllint (which comes with libxml2) or xmlwf (which comes with expat), or just with perl -MXML::Parser -e'XML::Parser->new( ErrorContext => 1)->parsefile( "yourfile.xml")'

Re: Parsing XML
by nobull (Friar) on May 29, 2005 at 08:18 UTC
    Have you valiated the failing XML with any other tools?