Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Hi perlmoks

I have a TMX file which looks like this one

<?xml version="1.0" encoding="UTF-8"?> <tmx version="1.4"><header creationtool="xx" creationtoolversion="1" s +egtype="sentence" o-tmf="undefined" adminlang="en" srclang="en" datat +ype="undefined"></header><body> <tu changedate="20180321T113135Z" creationdate="20180321T113135Z" chan +geid="user" tuid="1"> <prop type="client"> </prop> <prop type="project"> </prop> <prop type="domain"> </prop> <prop type="subject"> </prop> <prop type="corrected">no</prop> <prop type="aligned">no</prop> <tuv xml:lang="en"><seg>Hello <b>world!</b></seg></tuv> <tuv xml:lang="fr"><seg>Bonjour <b> monde</b></seg></tuv> </tu> <tu changedate="20180321T113135Z" creationdate="20180321T113135Z" chan +geid="user2" tuid="2"> <prop type="client"> </prop> <prop type="project">yes</prop> <prop type="corrected">no</prop> <prop type="aligned">no</prop> <tuv xml:lang="en"><seg>Hello <b>world!</b></seg></tuv> <tuv xml:lang="fr"><seg>Bonjour <b> monde</b></seg></tuv> </tu> </body> </tmx>

and I would like to export all the information in one line (tab separated).

I have the following code to export en and fr segments but it is not possible to export all other attributes.

use XML::LibXML; my $dom = 'XML::LibXML'->load_xml(IO => *STDIN); for my $child ( @{ $dom->find('/tmx/body/tu/tuv[@xml:lang=\'en\']/seg | /tmx/body/ +tu/tuv[@xml:lang=\'fr\']/seg | tmx/body/tu/prop | /tmx/body/tu/@creat +iondate') } ) { ( my $contents = join '', $child->childNodes ) =~ s,\n, <lb/> ,g; print $contents, $child->nodeName eq 'source' ? "\t" : "\n"; }

The ideal scenario would be to whatever props there are in the nodes and align them.

Could you please help me improve the code and sort it out?


In reply to Strip XML document by corfuitl

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (2)
    As of 2021-05-08 16:11 GMT
    Find Nodes?
      Voting Booth?
      Perl 7 will be out ...

      Results (96 votes). Check out past polls.