If you already have XML::Simple, then you probably already have XML::Parser as well (because the former typically depends on / uses the latter).

So here's a one-liner that does what you want via XML::Parser:

perl -MXML::Parser -e '$p=XML::Parser->new(Handlers=>{Char=>sub{print +"$_[1] "}}); $p->parsefile("filename.xml")'
(Note that the quotes as shown are based on using a bash shell or equivalent -- not ms-dos/cmd.exe.)

If the amount and types of white-space you get from that are not to your liking, you could either complicate the one-liner a little bit (add tr/ \n/ /s in the sub{}), or just pipe the output to another one-liner...

(updated last paragraph to improve the "tr///" suggestion; to clarify, here's a "really tidy" version of the one-liner:

perl -MXML::Parser -e '$p=XML::Parser->new(Handlers=> {Char=>sub{($_=$_[1])=~tr/ \n/ /s; s/^ +$//; print}}); $p->parsefile("filename.xml"); print "\n"'
which puts all the visible text on one line, then adds a final line-feed.)

In reply to Re: XML Parsing question by graff
in thread XML Parsing question by chtaylo2

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.