Took a stab at Option 1; need to test it more but looks promising.
my $dom = XML::LibXML->load_xml(string => <<'END_XML'); <?xml version="1.0"?> <office:document-content office:version="1.2" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"> <office:body><office:text> <text:p text:style-name="P1"> Fo<text:span text:style-name="T1">o<text:line-break/> B</text:span><text:span text:style-name="T3">a</text:span> <text:span text:style-name="T5">r<text:line-break/></text:span> </text:p> <text:p text:style-name="P3"> TEST is a &apos; real test. </text:p> </office:text></office:body> </office:document-content> END_XML my $xpc = XML::LibXML::XPathContext->new($dom); $xpc->registerNs('office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0'); $xpc->registerNs('text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0'); while (1) { my ($lb) = $xpc->findnodes('//text:line-break') or last; die "can't handle <text:line-break> with children: $lb" if $lb->hasChildNodes; my ($a) = $xpc->findnodes('ancestor::text:*[1]',$lb) or die "failed to find ancestor of $lb"; my ($a_a) = $xpc->findnodes('ancestor::*[1]',$a) or die "failed to find ancestor of ancestor of $a"; my $clone_a = $a->cloneNode(0); my $nextSibling = $lb->nextSibling(); while ( $nextSibling ) { my $currentSibling = $nextSibling; $nextSibling = $currentSibling->nextSibling(); $currentSibling = $a->removeChild($currentSibling); $clone_a->addChild($currentSibling); } $a->removeChild($lb); $a_a->insertAfter($clone_a,$a); } print $dom;
Which produces
<?xml version="1.0"?>
<office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" office:version="1.2">
<office:body><office:text>
<text:p text:style-name="P1">
    Fo<text:span text:style-name="T1">o</text:span><text:span text:style-name="T1">
    B</text:span><text:span text:style-name="T3">a</text:span>
    <text:span text:style-name="T5">r</text:span><text:span text:style-name="T5"/>
  </text:p>
<text:p text:style-name="P3">
  TEST is a ' real test.
  </text:p>
</office:text></office:body>
</office:document-content>

In reply to Re^2: fix ODT files with line breaks looking poor by melutovich
in thread fix ODT files with line breaks looking poor by melutovich

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.