The post above will give you an answer to your problem. Now I'm trying to persuade you from solving the problem in the way you want.

XML documents have a very strictly defined format. All conforming parsers will throw an exception for the input you describe, because the input is not XML and the "correct" thing to do is to reject the whole input file.

This makes sense when you use XML to transfer data between systems - you generally don't know much about the sending system, and if the input doesn't conform to the specs, the right attitude to take is that the other system has just thrown a bug or the stream has been mangled during transfer.

Again; your input is not XML. Trying to subvert the XML specs is fine by me, but you should not expect any standard XML tools to help you do it, and other developers/spec-writers will probably not understand all the subtleties involved. The full XML spec really is not as easy as you'd think from reading a couple of XML files. If you're diverting from it, you'd better make really sure you know what you're doing.


In reply to Re: Catch XML error by Joost
in thread Catch XML error by ecuguru

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.