Your problem is that your input files are not XML, XML files MUST have only one root node. All XML parsers are required to terminate if the input is not-well formed and if they are validating parsers then they also fail if the file is in-valid. Your file is not well formed and no XML parser will parse it, ever!

The only way to make this work is to cut your file up into logical chunks in their own <comp> nodes, or as you suggest put the whole file into it's own single root node. Which ever way you do it you must do it before you feed the data into the parser.

Why can't you load the file in, wrap it in a single root node and parse that? It easy easy to do.

Is there any reason why you can't load the file, and send each <comp> one at a time to the parser?

You may also wish to look at Tidy and xmllint which are tools that try to fix bad XML/HTML mark-up.


In reply to Re: Parsing with SAX an XML Document with no Root Node by ajt
in thread Parsing with SAX an XML Document with no Root Node by arunhorne

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.