Hi,

I've been chasing my tail for way to long on this one.

I basically have an XML document and want to remove the last incomplete tag so that I am left with the first two complete XML lines.

<?xml version="1.0" encoding="iso-8859-1" ?><TransactionPart Sub='PRFN +' Part='1' Id='ALAABADOCKAGDI'><Event Row='1' File='RELATIONSHIP_FILE +' ISN='23290' Time='2005/11/11-17:05:39' Op='Update'></TransactionPar +t> <?xml version="1.0" encoding="iso-8859-1" ?><TransactionPart Sub='PRF' + Part='1' Id='AABADOCKAGDI'><Event Row='1' File='RELATIONSHIP_FILE' I +SN='2180' Time='2005/11/11-17:05:39' Op='Update'></TransactionPart> <?xml version="1.0" encoding="iso-8859-1" ?><TransactionPart Sub='PRFN +' Part='1' Id='AABADOCKAGDI'><Event Row='1' File='PRODUCT_RELATIONSHI +P_FILE' ISN='1
I have tried pattern matching the last end tag and have managed to extract the last fragment:
my $terminator = "<\/notification>|<\/TransactionPart>"; $msg_payload =~ /($terminator?([^$terminator]*))$/; $truncate = $';
But the prematch doesn't give me the rest of the document, which is what I want.

So I tried to pattern match $truncate in the original string in the hopes of pulling out everything before it but that was sadly not to be for some unknown reason.

So what regexp magic can I use to extract the complete first n complete xml elements?

Many Thanks,
Starbuck


In reply to Regexp magic needed, truncate incomplete XML by starbuck

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.