I'm not sure, but it sounds like you might have invalid XML which means a "real" XML parser isn't going to work.

But, in any case, since you've already spent a ton of time fighting against a variety of full-fledged parsers, I'd just write my own parser. It actually is quite easy to write a real parser for whatever subset of XML one has to deal with. And that makes it trivial to deal with unusual things (that might not even strictly be valid XML) and trivial to get access to whatever matters to you.

Re^2: parsing XML fragments (xml log files) with... a regex shows how easy it was for me to deal with the types of XML I ran into. And the code is trivial to extend to cover more parts of XML to meet your needs.

Note that, as written, my code expects the full XML string. But it would be easy to modify it to just read a reasonably large chunk of text and, when pos gets 1/2 way through (or when an unclosed < is encountered), to just strip what has been parsed so far and append more.

- tye        


In reply to Re: Seeking for advice: XML parsing with special requirements (regex) by tye
in thread Seeking for advice: XML parsing with special requirements [Solved] by Nocturnus

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.