OpenOffice-OODoc - Re: insertParagraph -- path and position

Posted on Sat Sep 17 00:03:50 2005 by jmgdoc in response to 999 (See the whole thread of 2)
Re: insertParagraph -- path and position

If you want to insert a paragraph, you have to indicate an existing element, so the new paragraph is inserted before or after the given element.

An existing element can be selected by an XPath expression followed by a zero-based absolute position number. For example ("//text:p", 2) is the third paragraph and ("//text:h", 0) is the first header. So, if you want to insert a new paragraph before the 3rd existing paragraph, you can write
$doc->insertParagraph("//text:p", 2, position => 'before');
The 'position' option can be set to 'before' or 'after'; here, the new paragraph becomes the third one. With 'after' it would become the fourth.

Alternatively, if you previously got the third paragraph container, knowing that XPath query calculations are more time-consuming than direct element access, you should use it instead of the "path + absolute position", as below:
my $p = $doc->getParagraph(2); $doc->insertParagraph($p, position => 'before');
Write a response