I've been tasked with parsing some daily "xml" files and gathering data from them. I use "xml" as it is an abomination with a .xml extension. The issue is that in the file there are MANY Windows newlines intermixed with the valid Unix line feeds. This results in things like:

<FormattedReportObjects> <FormattedReportObject xsi:type="FormattedField" Type="xsd:long" FieldName="{Sum_ttx. E v e n t I D } " > <ObjectName>Field2</ObjectName> <FormattedValue>0</FormattedValue>
Where the newlines that LOOK correct are line feeds and where there is a line per character is a <CR><LF>.

Anyone have any ideas on how I could fix this? (The obvious "make your XML valid" has been tried and failed) I've tried tr, sed, and perl one liners, all to no avail. E.G.

perl -ne ' s/\r\n?//g; print ' foo.xml sed -e s/^M\n//g foo.xml tr -d ^M\n foo.xml
I appreciate any help anyone can provide. Thanks.


In reply to Scrubbing XML by the.duck

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.