in reply to XML::Parser and multiple results

An XML document can only have 1 (one) root. Hence your XML is not valid.

Fortunately XML::Parser has a Stream_Delimiter option:

* Stream_Delimiter
               This is an Expat option. It takes a string value. When this
               string is found alone on a line while parsing from a stream,
               then the parse is ended as if it saw an end of file. The
               intended use is with a stream of xml documents in a MIME multi‐
               part format. The string should not contain a trailing newline.

Replies are listed 'Best First'.
Re: Re: XML::Parser and multiple results
by Ineffectual (Scribe) on Feb 19, 2004 at 19:58 UTC
    I'm not really sure what this could do.. If I put a stream delimiter at the end of my really big file, will it parse all the way through it? If so, could I use that to load the entire file into a really big hash? Thanks. Ineff

      You don't have 1 XML document, as it is you have a number of them, in a single file. You coult insert stream delimiters between those documents to get XML::Parser to unserstand they they should be treated as separate XML documents.

      You could also wrap them all in a root tag, either in the main file, or by using an entity that includes it, see Re: XML log files.

      Oh, and I found a FAQ about it in the XML::Twig FAQ :--)

      You really have to understand that at this point you don't have XML. If it doesn't parse, then it is not XML. If you want to have XML you have to get your data to be XML, or to use the mildly hacky stream delimiter option.