.\" Automatically generated by Pod::Man 2.27 (Pod::Simple 3.28) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "OODoc::XPath 3pm" .TH OODoc::XPath 3pm "2013-12-25" "perl v5.18.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" OpenOffice::OODoc::XPath \- Low\-level navigation in the documents .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module is a low-level class which uses OODoc::File (without inheriting anything from it) along with the classes defined in the XML::Twig module. It's a common basis for the other, more user\- friendly, document-oriented modules. It uses XPath expressions in order to retrieve any document element (but it doesn't provide a full implementation of the XPath standard). In addition, while the most part of the provided methods are OpenDocument-aware, this module could be used against any other kind of \s-1XML\s0 documents, simply because it benefits from all the features of XML::Twig. Such a possibility may prove useful for applications that simultaneously process OpenDocument and non-OpenDocument \s-1XML\s0 files. .PP The OpenOffice::OODoc::XPath class should not be explicitly used in the applications, because all its features are available in more user-friendly classes such as OODoc::Text, OODoc::Styles, OODoc::Image, OODoc::Document and OODoc::Meta. The present manual page is provided to describe the common methods and properties that are available with all these classes. .PP This chapter can be skipped by programmers who are only interested in upper level methods provided by the OODoc::Text, ::Styles, ::Image and ::Meta modules. Understanding these modules is easier and using them requires less Perl and \s-1XML\s0 expertise. However, calling OODoc::XPath methods remains a good rescue option as it allows all kinds of operations on all types of \s-1XML\s0 elements contained in any OpenDocument-compliant file. .PP OODoc::XPath is the common foundation of OODoc::Meta, OODoc::Text, OODoc::Styles and OODoc::Image. It contains the lowest layer of navigation services for \s-1XML\s0 documents and handles the link with OODoc::File for file access. Its primary role is as an interface with the XML::Twig \s-1API.\s0 .PP In the present manual chapter, you will see \*(L"elements\*(R" often mentioned. When it says that a module expects a parameter or returns an element (either singly or as a list), it is referring to an \s-1XML\s0 element. It is important to distinguish elements from their content (elements being simply references to \s-1XML\s0 data structures). To read or modify the content of an element such as its text or \s-1XML\s0 attributes, use the accessors also available within OODoc::XPath. .PP In most cases where XPath methods require a reference to an element as an argument, there are two ways of proceeding: .PP \&\- reference the element directly (obtained previously) .PP \&\- or give an XPath expression and a position, being a string and an integer respectively; for example, the pair ('//office:body/text:p', 12) or ('//text:p', 12) represents the thirteenth occurrence of the 'text:p' element, i.e. the 13th paragraph (occurrences are numbered starting from 0). .PP The second way requires the knowledge of an appropriate XPath expression (according the OpenDocument \s-1XML\s0 format specification). And a given XPath expression is not necessarily the same with an OpenDocument as in an OpenOffice.org document. So you should preferently use high level accessors (provided by derivative classes such as OODoc::Document) and avoid XPath hardcoding. However, you know you can at any time reach any element with XPath. .PP Of course, you will never need to use XPath expressions in order to reach the most common text elements (such as paragraphs), because the OODoc::Text module provides more friendly accessors (for example, you will probably use the \fIgetParagraph()\fR method and forget \*(L"//text:p\*(R"). .PP Some methods accept both forms which means that if the first parameter is recognised as an element reference, the position does not need to be given. Therefore the number of arguments for certain OODoc::XPath methods can vary. .PP For those who really want to access all areas there are also OODoc::XPath methods which allow unrestricted access to every element or \s-1XML\s0 attribute via an access path in XPath syntax. If you are into this kind of thing, we recommend you obtain good syntax reference manuals for XPath and OpenDocument and a supply of aspirin. .PP Methods which may return several lines of text (e.g. getTextList) do so either in the form of an unique character string containing \*(L"\en\*(R" separators or in table form. .PP Unless otherwise stated, the word 'document' in this chapter only refers to \s-1XML\s0 documents contained within OODoc::XPath objects and not, say, OpenDocument files (as an end user would use). .PP Amongst the different methods which return elements, attributes or text, some are called getXxx, others selectXxx or findXxx. Read methods whose names start with \*(L"get\*(R" generally refer to an unfiltered object or list, whereas others return an object or list filtered according to a parameter value. In this latter case the search parameter is treated as a standard expression and not an exact value. This means that if the search criteria is \*(L"xyz\*(R", all text containing \*(L"xyz\*(R" will be considered a match. To restrict the search to text exactly equal to \*(L"xyz\*(R", use \*(L"^xyz$\*(R" as the search criteria (following Perl regular expression syntax). .PP Several methods allow you to place copies of or references to elements (from other documents or from other positions in the same document) in any position in the current document. This offers powerful manoeuvrability but only if these placements conform with the destination position's context. .PP For example, you can easily copy a paragraph from one document to another but only if you knowingly modify the paragraph's style attribute if that style is not already defined in the destination document. You can also copy the style but only if you are sure that this style is not already defined by another unknown style in the destination document (and so on). .PP For advanced users familiar with the XML::Twig \s-1API,\s0 it might be interesting to know that all the objects called \*(L"elements\*(R" in the following chapters are objects of the OpenOffice::OODoc::Element class, which is an XML::Twig::Elt derivative. So all methods associated with this class are directly applicable to these elements, on top of the functionality described in this manual. However, the knowledge of XML::Twig is not mandatory. .PP Important note: The applications should not explicitly work with this class. We recommend using OODoc::Meta and OODoc::Document (which are both OODoc::XPath derivatives). These two objects provide highest-level methods which are neater and more productive. Explicit use of OODoc::XPath methods (which sometimes require large numbers of parameters) should only be considered as a last resort in unexpected circumstances for access to any element or \s-1XML\s0 attribute not handled by more friendly methods. However, the present manual chapter could prove helpful because all the common features of OODoc::Meta and OODoc::Document are described here. .SS "Methods" .IX Subsection "Methods" \fIConstructor : OpenOffice::OODoc::XPath\->new();\fR .IX Subsection "Constructor : OpenOffice::OODoc::XPath->new();" .PP .Vb 1 \& Short Form: odfXPath() \& \& Returns a new OpenDocument connector, i.e. an interface which \& can be used for subsequent operations on a well\-formed document. \& \& This constructor should not be called directly; it\*(Aqs implicitly \& triggered each time a Meta or Document object is created. So the \& following description apply to odfMeta() and odfDocument(). \& \& The document is loaded and parsed according to various options. \& The most used option is \*(Aqfile\*(Aq; it simply allows the application \& to process an OpenDocument file selected by its path/name in the \& file system. \& \& Example: \& \& my $doc = odfXPath \& ( \& file => "myfile.ods", \& part => "content" \& ); \& # ... lot of processing ... \& $doc\->save; \& \& Returns a new document connector. In the example above, the object \& is loaded from a regular OpenDocument file, that is the most current \& option, but there are other possibilities. It\*(Aqs possible to use \& flat XML (available as a string in memory, or loaded from a file). \& In addition, this constructor is able to create a new document \& from scratch. \& \& The value of the \*(Aqfile\*(Aq option may be an open IO::File object, \& that allows the application to use an application\-provided file \& handle. However, you should prefer file paths/names when possible, \& and read the explanations about the constructor and the save() method \& in the OpenOffice::OODoc::File manual page before using open file \& handles. Remember that, as soon as the given file or handle is \& an ODF container, OODoc::XPath uses OODoc::File. \& \& Parameters are named (hash key => value). The constructor must get \& at least one parameter giving a means of obtaining the XML document \& that it will represent. Several options are available; each one is \& represented through the following examples: \& \& # option 1 (using an existing flat XML document) \& my $doc = odfXPath(xml => $xml_string); \& \& # option 2 (using a previously created ODF file interface) \& my $oofile = odfContainer(\*(Aqsource.odt\*(Aq); \& my $doc = odfXPath(container => $oofile, part => \*(Aqmeta\*(Aq); \& \& # option 3 (using a regular ODF file directly) \& my $doc = odfXPath(file => \*(Aqsource.odt\*(Aq, part => \*(Aqcontent\*(Aq); \& \& # option 4 (multiple instances against a single file) \& my $content = odfXPath(file => \*(Aqsource.odt\*(Aq, part => \*(Aqcontent\*(Aq); \& my $meta = odfXPath(file => $content, part => \*(Aqmeta\*(Aq); \& my $styles = odfXPath(file => $content, part => \*(Aqstyles\*(Aq); \& \& Remember "odfXPath()" represents "OpenOffice::OODoc::XPath\->new()" \& in the instructions above, and you can (and should) use this shortcut \& provided that you have loaded the main OpenOffice::OODoc module, and \& not only and explicitly the OpenOffice::OODoc::XPath module. \& \& The first form uses an XML string directly (previously loaded or \& created by the program). To be used for very specific applications \& working with flat XML documents exports and not with standard \& OOo/OpenDocument files. \& \& The second method links OODoc::XPath to an existing OODoc::File \& object (through the "container" option) and indicates which XML part it \& is to extract (metadata, content, styles, etc). The OODoc::File is an \& abstraction of an already open ODF container. It can be shared, i.e. \& several OODoc::XPath objects can be instantiated with the same \& OODoc::File object, and this possibility must be used when \& several OODoc::XPath objects have to bring consistent changes in \& a single file (see option 4 below). In order to create the \& required OODoc::File object, simply use odfFile() with a filename \& as argument (for advanced use, see OpenOffice::OODoc::File). \& \& The third method is the easiest, because the user just provide \& a filename and a member, and all the file interface is run silently \& (i.e. an invisible OODoc::File object is automatically created and \& used to get the content). It\*(Aqs probably the most used approach; its \& recommended when the user doesn\*(Aqt need to get more than one member \& in the same file. \& \& The \*(Aqpart\*(Aq option is a selector that tells what component is needed \& (content, styles, metadata, ...) knowing that an OODoc::XPath object \& can handle only one component. Its default value is \*(Aqcontent\*(Aq. \& \& Note that the \*(Aqpart\*(Aq option replaces the deprecated \*(Aqmember\*(Aq option. \& However, for compatibility reasons, \*(Aqmember\*(Aq is supported yet (if \& both \*(Aqmember\*(Aq and \*(Aqpart\*(Aq are erroneously provided, \*(Aqmember\*(Aq prevails). \& \& If the application needs to process, say, the content and the styles \& in the same session, it must create two, or more, OODoc::XPath objects \& possibly associated with the same file interface. The appropriate way \& is shown in our last example above. The first instance is associated \& with a filename. Then the other instances are created with the first \& one, provided as the value of the \*(Aqfile\*(Aq option instead of a filename. \& The constructor tries to be user\-friendly: if the \*(Aqfile\*(Aq value is \& a character string, it\*(Aqs regarded as a filename, but if this value, \& is an existing OpenOffice::OODoc::XPath object, the new object is \& automatically connected to the same file interface as the other one. \& The file interface is transparently provided by a common shared \& OpenOffice::OODoc::File object (you can safely ignore the features \& of this object, but a corresponding manual chapter is available for \& more details). \& \& Be careful: creating more than one OpenOffice::OODoc::XPath objects \& linked by their \*(Aqfile\*(Aq parameters to the same explicit filename (and \& not linked with each other) produces useless extra I/O operations and \& possible conflicts. \& \& Caution: being associated with a common interface via OODoc::File, \& none of these OODoc::XPath objects should be deleted before the final \& save() call for this archive. So by calling a save, the File object \& "calls up" all the XPath objects which were "connected" to it in order \& to "ask" each of them for the changes which were made to the XML \& (content, styles, meta, etc.). The results are unpredictable if any \& of them is absent when called. \& \& If the provided filename has a ".xml" or ".XML" suffix, or whatever \& the name if the \*(Aqflat_xml\*(Aq option is set to 1, the file is processed \& as flat XML and not as a regular OOo file. No OODoc::File object is \& created, and the result of a subsequent call of the save() method \& produces a flat XML export (and not a regular OOo/OpenDocument file). \& \& You can pass the optional parameter \*(Aqelement\*(Aq in any case where the \& constructor is called without the \*(Aqxml\*(Aq parameter. Bearing in mind \& that an OODoc::XPath object will not necessarily handle an entire \& XML document, this extra parameter indicates the name of the XML \& element to be loaded and handled. If the \*(Aqelement\*(Aq parameter is not \& given for an OpenDocument file, a default element will be chosen \& according to the following table: \& \& \*(Aqmeta\*(Aq => \*(Aqoffice:document\-meta\*(Aq \& \*(Aqcontent\*(Aq => \*(Aqoffice:document\-content\*(Aq \& \*(Aqstyles\*(Aq => \*(Aqoffice:document\-styles\*(Aq \& \*(Aqsettings\*(Aq => \*(Aqoffice:document\-settings\*(Aq \& \*(Aqmanifest\*(Aq => \*(Aqmanifest:manifest\*(Aq \& \& Conversely, the \*(Aqelement\*(Aq parameter becomes mandatory if the chosen \& XML element is not listed above. Through OODoc::File, OODoc::XPath \& can actually access archives which are not necessarily in \& OpenDocument format and may be, for example, "databases" of \& presentation and content templates. \& \& If the application needs to create a new document, and not process \& an existing one, an additional option must be passed: \& \& create => "" \& \& where "class" must be one of the following list: "text", \& "spreadsheet", "presentation" or "drawing", according to the needed \& content class. And, for very special needs, the user can pass an \& additional "template_path" to select an ad hoc directory of XML \& templates instead of the default one. This user\-provided directory \& must have the same kind of structure and content as the "templates" \& subdirectory of the OpenOffice::OODoc installation. \& \& An additional \*(Aqopendocument\*(Aq option can be provided and set to \*(Aqtrue\*(Aq \& or \*(Aqfalse\*(Aq. If this option is \*(Aqfalse\*(Aq, the new document is created \& according to the OpenOffice.org 1.0 format instead of the OASIS \& OpenDocument format. The default format is OpenDocument. The \& \*(Aqopendocument\*(Aq option works for new documents only and is ignored \& unless the \*(Aqcreate\*(Aq option. This module can create and process either \& OpenOffice.org 1.0 documents or ODF documents but can\*(Aqt directly \& convert a document from one format to the other one. \& \& OODoc::XPath can process ODF documents provided through XML flat \& files as well as in the compressed (zip) format. The given file is \& automatically processed as flat XML if either it\*(Aqs name ends by ".xml" \& or the \*(Aqflat_xml\*(Aq option is set to \*(Aq1\*(Aq. When processing a flat XML \& file, OODoc::XPath doesn\*(Aqt load the OODoc::File zip interface. So, \& a subsequent call of the save() method can only export the document \& as flat XML. \& \& An optional \*(Aqreadable_XML\*(Aq can be passed. If this option is provided \& and set to \*(Aqon\*(Aq or \*(Aqtrue\*(Aq, the resulting XML will be smartly indented \& (and, of course, more space\-consuming). This feature is intended for \& debugging purposes and should not be used in production. \& \& The \*(Aqlocal_encoding\*(Aq option can be set with the appropriate value \& when a particular character set (and not the default one) must be \& used for a document. \& \& A \*(Aqread_only\*(Aq can be provided and set to \*(Aqtrue\*(Aq in order to prevent \& the current member from being written back to the physical ODF file \& when the save() method is called. \& \& Other optional parameters can also be passed to the constructor (see \& Properties below). .Ve .PP \fIappendElement(path, position, name/xml, [options]);\fR .IX Subsection "appendElement(path, position, name/xml, [options]);" .PP \fIappendElement(element, name/xml, [options]);\fR .IX Subsection "appendElement(element, name/xml, [options]);" .PP .Vb 3 \& Adds a new element or existing element to the list of child elements \& of an existing parent element given first (by [path, position] or by \& reference). \& \& The argument after the position argument can be an XML element name. \& \& Example: \& \& $content\->appendElement \& ( \& \*(Aq//office:body\*(Aq, 0, \*(Aqtext:p\*(Aq, \& text => "New text" \& ); \& \& adds a paragraph containing the phrase "New text" to the end of the \& document body. (Remember that in the case of an OpenDocument text \& file (Writer), it would be better to use the appendParagraph method of \& OpenOffice::OODoc::Text as this requires fewer parameters. \& \& If the \*(Aqtext\*(Aq option is omitted, an empty element is created (in the \& above example it would be an empty paragraph or line feed). \& \& You can pass the \*(Aqattributes\*(Aq option which is a hash whose keys are the \& XML attribute names and whose values are the XML attribute values. Use \& of these options depends on the type of document and the type of element \& and requires knowledge of OpenDocument conventions. \& \& Example: \& \& $my_style = \& { \& \*(Aqstyle:name\*(Aq => \*(AqP1\*(Aq, \& \*(Aqstyle:family => \*(Aqparagraph\*(Aq \& }; \& \& $content\->appendElement \& ( \& \*(Aq//office:automatic\-styles\*(Aq, 0, \*(Aqstyle:style\*(Aq, \& attributes => $my_style \& ); \& \& creates a new paragraph style called \*(AqP1\*(Aq in the list of "automatic \& styles" ("automatic styles" are styles which are not explicitly \& indicated in the styles list as it appears to the end user). \& \& This method lets you add any kind of element into a document, even \& exotic ones. With the most common OpenDocument objects (e.g. \& paragraphs), though, it is easier to use the specialist methods \& contained in other modules. \& \& The \*(Aqname\*(Aq argument can be replaced by an existing element in the \& same OODoc::XPath object or in another. In which case no element is \& created but the existing element is simply referenced with a new \& position even though it remains in its old position. Caution: any \& modification of an element which is referenced several times in one \& or more documents is made to all references. If you want to add a \& similar but separate element, you must use replicateElement which \& produces a new element from the content of an existing one. \& \& The \*(Aqname\*(Aq argument can also be replaced by an XML string. This \& string must correspond to the correct XML description of a UTF\-8 \& encoded OpenDocument element. For example, it could be a \& string which had been previously exported using the exportXMLElement \& method of OODoc::XPath, or extracted from an OpenDocument file by \& some other application. If for any reason you absolutely have to \& use a non\-UTF8 XML string which contains 8\-bit characters (accented \& letters, etc.), you can always convert the string using the \& encode_text method before passing it to appendElement. Of course, \& the problem will not arise if you are absolutely sure that the string \& only contains ASCII (7 bit) characters. XML syntax is checked, but it \& is up to the user to verify that the element import conforms to \& OpenDocument XML grammar. \& \& The following piece of code produces the same result as the first \& example: \& \& $xml = \*(Aq\*(Aq . \& \*(AqNew text\*(Aq . \& \*(Aq\*(Aq; \& $content\->appendElement \& ( \& \*(Aq//office:body\*(Aq, 0, $xml \& ); \& \& Using this method, after one or more element creations by direct \& importation of XML strings, it might be useful to call the \& reorganize method (but not absolutely necessary). .Ve .PP \fIappendBodyElement(element [, options])\fR .IX Subsection "appendBodyElement(element [, options])" .PP .Vb 2 \& Copies an existing element of any type and appends it to the end of \& the document body. No new element is created. .Ve .PP \fIappendLineBreak(element)\fR .IX Subsection "appendLineBreak(element)" .PP .Vb 3 \& Appends a line break to a text element. This method allows the user \& to create a single text element (ex: a paragraph) including one or \& more breaks, instead of separate elements. \& \& The example below appends a new text in a new line to the end of \& an existing paragraph: \& \& my $p = $doc\->getElement(\*(Aq//text:p\*(Aq, 5); \& $doc\->appendLineBreak($p); \& $doc\->extendText($p, \*(AqA new line in the same paragraph\*(Aq); .Ve .PP \fIappendSpaces(element, length)\fR .IX Subsection "appendSpaces(element, length)" .PP .Vb 4 \& Appends a sequence of multiple spaces to a text element, knowing that \& a string containing repeated spaces shouldn\*(Aqt be stored as is in a \& document (see setText() and spaces() for details about repeated \& spaces). .Ve .PP \fIappendTabStop(element)\fR .IX Subsection "appendTabStop(element)" .PP .Vb 1 \& Appends a tab stop ("\et") to a text element. .Ve .PP \fIblankSpaces(length)\fR .IX Subsection "blankSpaces(length)" .PP .Vb 1 \& See spaces(). .Ve .PP \fIcloneContent(oodoc_xpath_object)\fR .IX Subsection "cloneContent(oodoc_xpath_object)" .PP .Vb 3 \& Cancels the entire document contents of the current instance and \& replaces it with a reference to the contents of another OODoc::XPath \& object. \& \& Example: \& \& $doc1 = OpenOffice::OODoc::XPath\->new \& ( \& file => \*(Aqtemplate.ods\*(Aq, \& member => \*(Aqstyles\*(Aq \& ); \& $doc2 = OpenOffice::OODoc::XPath\->new \& ( \& file => \*(Aqsheet.ods\*(Aq, \& member => \*(Aqstyles\*(Aq \& ); \& $doc2\->cloneContent($doc1); \& $doc2\->save; \& \& This sequence replaces the styles and page layout of \*(Aqsheet.ods\*(Aq \& with those of \*(Aqtemplate.ods\*(Aq. \& \& The above example could easily have been written without even using \& OODoc::XPath by acting directly on the files. For example, extract \& the \*(Aqstyles.xml\*(Aq member from \*(Aqtemplate.ods\*(Aq and insert it into \& \*(Aqsheet.ods\*(Aq. The use of OODoc::XPath and the cloneContent method \& guarantees that the transferred content corresponds to an \& OpenDocument document and allows reads/writes to it on the fly. \& \& Caution: the "cloned" content is not physically copied. Calling this \& method references one single physical content in two documents. Any \& modifications made to the content of either of these two documents \& applies equally to the other and vice\-versa. .Ve .PP \fIcontentClass([class name])\fR .IX Subsection "contentClass([class name])" .PP .Vb 4 \& Accessor to get or set the class of the document content. If the \& current member is a document content, returns its class according \& to the OpenDocument terminology, i.e. one of the following values: \& "text", "spreadsheet", "presentation", or "drawing". \& \& Returns an empty string if the current member is not a document \& content (if it\*(Aqs, for example, the "meta" or "styles" member). \& \& This accessor is read\-only. .Ve .PP \fIcreateSpaces(length)\fR .IX Subsection "createSpaces(length)" .PP .Vb 1 \& See spaces(). .Ve .PP \fIcreateElement(name, text)\fR .IX Subsection "createElement(name, text)" .PP \fIcreateElement(xml)\fR .IX Subsection "createElement(xml)" .PP .Vb 2 \& Creates a new element without attributes which is not inserted in a \& document. \& \& Example: \& \& my $element = \& $doc\->createElement \& (\*(Aqmy_element\*(Aq, \*(Aqits content\*(Aq); \& \& creates a new XML element without attributes and returns its \& reference. \& \& Instead of a name, the first argument can be the full XML \& description of the element. Example: \& \& my $element = $doc\->createElement \& (\*(AqMy text\*(Aq); \& \& This new element is temporary: it is not linked to any document. It \& is destined to be used later by another method. \& \& The name can contain a namespace prefix which would look like this: \& \*(Aqnamespace:name\*(Aq. \& \& In its second form, a well\-formed XML string can be supplied as a \& single argument. The recognition criteria is the presence of the "<" \& character at the beginning of the argument. See appendElement for \& comments on the direct insertion of XML. \& \& Explicit calls to createElement() should be rare. This method is \& normally called silently by higher\-level methods which are capable \& of creating an element, inserting it in a document\*(Aqs XML tree and \& giving it attributes (see appendElement and insertElement). .Ve .PP \fIcreateFrame(name => frame_name [, options])\fR .IX Subsection "createFrame(name => frame_name [, options])" .PP .Vb 3 \& Creates an empty frame. A frame is an OpenDocument object which \& controls a rectangular area where a visible content is displayed. \& Possible contents for a frame are text boxes or images. \& \& This method works is not focused on a particular document class \& (for example, it works on text documents as well as on presentations), \& but the visible effects of some options are not always exactly the \& same. \& \& Possible options are: \& \& \*(Aqname\*(Aq => unique name \& \& The \*(Aqname\*(Aq is an identifier; if provided, it should be unique for \& the document. \& \& \*(Aqattachment\*(Aq => existing container \& \& The value of this option, if provided, must be an existing element \& which can contain a text box according to the OpenDocument rules. \& Such an object may be, for example, a draw page if the current \& document class is \*(Aqpresentation\*(Aq or \*(Aqdrawing\*(Aq, or a paragraph if \& this class is \*(Aqtext\*(Aq. \& \& \*(Aqpage\*(Aq => page number or name \& \& The effects of the \*(Aqpage\*(Aq option depends on the content class of the \& current document. If this option is used, it indicates that the frame \& will be anchored to a page, and the given value is a page number. \& It does not matter if, when createFrame() is called, this number is \& beyond the end of the document or not. If the content class of the \& document is "presentation" (Impress) or "drawing" (Draw), then the \& page option must be either the visible name or the object reference \& of an existing draw page. Caution: the \*(Aqpage\*(Aq option is ignored if \& \*(Aqattachment\*(Aq is provided; in the other hand, either \*(Aqpage\*(Aq or \& \*(Aqattachment\*(Aq nust be provided in order to really include the new frame \& in the document. \& \& \*(Aqposition\*(Aq => coordinates \& \& The coordinates are provided as a string. They go from left to right \& and top to bottom. Coordinates should be given here in the form of a \& string "x,y", and the default unit is centimeter. You can choose \& any other OpenDocument\-supported unit instead by attaching the \& corresponding usual abbreviation, such as "12.5cm, 35mm" which is the \& same as "125mm, 3.5cm" or "12.5,3.5", etc. The point ("pt") unit is \& allowed as well. The default coordinates are "0, 0". By default, \& the coordinates are relative to the anchor point. So, the coordinates \& are directly page\-related if a valid \*(Aqpage\*(Aq option is provided only, \& but if the box is attached to, say, a paragraph, the origin of the \& coordinates is the beginning of the paragraph. However, the real \& interpretation of the coordinates depends on the style. With some \& style definitions, the coordinates may just be ignored (ex: if the \& style says "the frame is centered", OpenOffice.org will center the \& frame whatever its stored coordinates). According to other possible \& style definitions, the coordinates could be counted from the right \& and/or from the bottom and not from the left/top. \& \& \*(Aqsize\*(Aq => the size of the box \& \& Provided using as a string using the same syntax and units as the \& position, the \*(Aqsize\*(Aq option is strongly recommended knowing that a \& sizeless frame couldn\*(Aqt be properly displayed. The width comes \& first in the string. The height is sometimes ignored, according to \& the style of the frame: by default, the display height of a text box \& (which is a particular frame) is automatically adjusted to the \& content. \& \& \*(Aqstyle\*(Aq => style name \& \& The \*(Aqstyle\*(Aq option allows the application to set the frame style. \& Caution, a text style can\*(Aqt be used as a frame style. A frame \& style controls the box properties only (border, background, shadow, \& and so on), and not the content properties. Reusing an existing frame \& style through this option is generally a good idea. .Ve .PP \fIcurrentContext([context])\fR .IX Subsection "currentContext([context])" .PP .Vb 2 \& Accessor allowing the application to change the context for some \& search methods (including getElement()). \& \& The default context is the root of the document. By setting the \& current context to a lower level object, the application can restrain \& the search to the descendants of this object. \& \& In the example below, the getElement() method retrieves a paragraph \& by order number in a previously selected section, and not in the whole \& document. \& \& my $section = $doc\->getElement("//text:section", $s_number); \& $doc\->currentContext($section); \& my $paragraph = $doc\->getElement("//text:p", $p_number); \& \& Without argument, simply returns the previous current context. \& \& See also resetCurrentContext(). .Ve .PP \fIdecode_text(utf8_string)\fR .IX Subsection "decode_text(utf8_string)" .PP .Vb 2 \& Caution: this method is a non\-exported class method. It must be used \& like this: \& \& OpenOffice::OODoc::XPath::decode_text($utf8_string); \& \& and not from an OODoc::XPath instance. \& \& Decodes a UTF\-8 string and returns an 8 bit character translation \& of it out of the user\*(Aqs character set, as defined by the following \& variable: \& \& $OpenOffice::OODoc::XPath::LOCAL_CHARSET \& \& for which the default value is \*(Aqiso\-8859\-1\*(Aq. See the Perl/Encode \& manual for the list of supported character sets. \& \& OpenDocument uses UTF\-8 XML encoding. \& \& Explicit calls to this method should be rare. It is used internally \& by methods which return text extracted from document content (e.g. \& getText). \& \& Warning to contributors: any method which returns text extracted \& from ODF documents is based on decode_text; so any modification or \& improvement of the decoding logic should be made there. .Ve .PP \fIencode_text(editable_string)\fR .IX Subsection "encode_text(editable_string)" .PP .Vb 1 \& Class method. \& \& Encodes "local" character strings (for writing to ODF documents). \& \& Example: \& \& $string = OpenOffice::OODoc::encode_text($local_string); \& \& The local character string is defined by the following global \& variable: \& \& $OpenOffice::OODoc::XPath::LOCAL_CHARSET \& \& for which the default value is \*(Aqiso\-8859\-1\*(Aq. \& \& Explicit calls to this method should generally be avoided. It is \& used internally by methods which insert text or attribute values \& into documents (e.g. setText). .Ve .PP \fI\fIdispose()\fI\fR .IX Subsection "dispose()" .PP .Vb 3 \& Deletes the calling document object. Recommended as soon as the \& object is no longer needed by the application, and sometimes \& mandatory to avoid memory leaks, especially in long\-running processes. .Ve .PP \fI\fIexportXMLBody()\fI\fR .IX Subsection "exportXMLBody()" .PP .Vb 2 \& Returns the XML string for use by another application representing \& the body of a document, without UTF8 decoding. .Ve .PP \fI\fIexportXMLContent()\fI\fR .IX Subsection "exportXMLContent()" .PP .Vb 1 \& See getXMLContent() .Ve .PP \fIexportXMLElement(path, position)\fR .IX Subsection "exportXMLElement(path, position)" .PP \fIexportXMLElement(element)\fR .IX Subsection "exportXMLElement(element)" .PP .Vb 3 \& Returns the XML string which represents a particular document \& element (style definition, paragraph, table cell, object, etc.) for \& use by another application without UTF8 decoding. \& \& This method is principally designed to allow remote exchanges of \& elements between programs using any XML storage or transfer method. \& It acts as "sender" whilst the "receiver" can use appendElement or \& insertElement (for example) to insert any exported elements into a \& document. Example: \& \& # sender programme \& # ... \& open (EXPORT, "> transfer.xml"); \& print EXPORT $doc\->exportXMLElement(\*(Aq//text:p\*(Aq, 15); \& close EXPORT; \& \& # receiver programme \& # ... \& open (IMPORT, "< transfer.xml"); \& $doc\->appendElement(\*(Aq//office:body\*(Aq, 0, ); \& close (IMPORT); \& \& In this example, a paragraph is transferred but it could just as \& easily be any content, presentation or metadata element. \& \& Conversely, this method is not needed when transferring an element \& from one document to another in the same program (or from one \& document position to another). An element can be copied directly \& from within the same program by reference or replication without \& going via its XML (see appendElement(), insertElement() and \& replicateElement()). .Ve .PP \fIextendText(path, position, text [, offset])\fR .IX Subsection "extendText(path, position, text [, offset])" .PP \fIextendText(element, text [, offset])\fR .IX Subsection "extendText(element, text [, offset])" .PP .Vb 3 \& Appends the given text to the previous content of the given \& element. If the optional \*(Aqoffset\*(Aq element is provided, the \& new element is inserted at the given position. \& \& Example: \& \& $doc\->setText($p, "Initial content"); \& $doc\->extendText($p, " extended"); \& \& Assuming $p is a regular text element (ex: a paragraph), its \& content becomes "Initial content extended". \& \& If the second argument is an element itself, it\*(Aqs appended \& as is to the first element. This feature can be used, for \& example, in order to append sequences of repeated spaces: \& \& $doc\->setText($p, "Begin"); \& $spaces = $doc\->spaces(6); \& $doc\->extendText($p, $spaces); \& $doc\->extendText($p, "End"); \& \& After the code sequence above, the $p element contains: \& \& "Begin End" \& \& knowing that a single string containing repeated spaces could \& not be properly processed by extendText(), even if the \& \*(Aqmultiple_spaces\*(Aq property is set (this property affects the \& setText() method only). \& \& (See also setText()). .Ve .PP \fIfindElementList(element, filter [, replacement])\fR .IX Subsection "findElementList(element, filter [, replacement])" .PP .Vb 2 \& Returns all the children of the given element whose content matches \& the given filter (regexp). \& \& If the third argument (\*(Aqreplacement\*(Aq) is given, every string which \& matches the filter in each child element will be replaced by this \& \*(Aqreplacement\*(Aq value. This \*(Aqreplacement\*(Aq argument can be a character \& string or a function reference. (See replaceText() method below.) \& \& Filtering and possible replacement only affects an element\*(Aqs content \& and not its attributes. \& \& This method is mostly for internal use. We recommend using other \& methods for the selective extraction of elements. .Ve .PP \fIflatten(element)\fR .IX Subsection "flatten(element)" .PP .Vb 5 \& Converts in place the content of the given element to a flat string, \& removing any structure. Same as $element\->flatten() (see flatten() \& in the "Element methods" section below). If no element is provided, \& "flattens" the current context element, which is, by default, the \& root of the document (be careful !). .Ve .PP \fIgetAttribute(path, position, name)\fR .IX Subsection "getAttribute(path, position, name)" .PP \fIgetAttribute(element, attribute_name)\fR .IX Subsection "getAttribute(element, attribute_name)" .PP .Vb 1 \& Returns the value of a given attribute in a given element. \& \& The element is the first argument, the name of the attribute the second \& one. The return value is undef if the attribute is not defined in the \& given element. \& \& Example: \& \& my $element = $doc\->getElement(\*(Aq//text:p\*(Aq, 15); \& my $style = $doc\->getAttribute($element, \*(Aqtext:style\-name\*(Aq); \& \& returns the style for paragraph 15. \& \& If the given attribute name doesn\*(Aqt include a namespace prefix, the \& namespace of the attribute is automatically supposed to be the same as \& the namespace of the element. In addition, any blank space within the \& attribute name is regarded as a \*(Aq\-\*(Aq. So, the same example could be \& be written more concisely as shown below: \& \& my $element = $doc\->getElement(\*(Aq//text:p\*(Aq, 15); \& my $style = $doc\->getAttribute($element, \*(Aqstyle name\*(Aq); .Ve .PP \fIgetAttributes(path, position)\fR .IX Subsection "getAttributes(path, position)" .PP \fIgetAttributes(element)\fR .IX Subsection "getAttributes(element)" .PP .Vb 2 \& Returns a list of the element\*(Aqs attributes in the form of a hash \& whose keys are the attributes\*(Aq XML names. .Ve .PP \fI\fIgetBody()\fI\fR .IX Subsection "getBody()" .PP .Vb 3 \& Returns the root of the document body. The document body is the \& main container of all the displayable content not including page \& headers, page footers, and page backgrounds. .Ve .PP \fIgetDescendants(tag [, context])\fR .IX Subsection "getDescendants(tag [, context])" .PP .Vb 2 \& Returns the list of the descendants of the given context element \& matching the given tag. Example: \& \& my $section = $doc\->getSection("SectionName"); \& my @paragraphs = $doc\->getDescendants(\*(Aqtext:p\*(Aq, $section); \& \& Here, @paragraphs is the list of all the paragraphs which are the \& descendants (at every level) of a given section (the getSection() \& method is described in the OpenOffice::OODoc::Text chapter). \& \& If the second argument is not provided, the current context of the \& document is used (see currentContext()). .Ve .PP \fIgetElement(path [, position [, context]])\fR .IX Subsection "getElement(path [, position [, context]])" .PP .Vb 6 \& This method is provided in order to allow the user to retrieve any \& element in any kind of XML document (ODF\-compliant or not) using an \& application\-provided XPath expression. It should be used with elements \& whose type is not explicitly supported by the more focused (and more \& user\-friendly) methods, described in other manual chapters (::Text, \& ::Styles, ::Meta, and ::Document). \& \& This method returns an element\*(Aqs reference. \& \& The position argument is used to select a particular element, in the \& order of the document, knowing that the given XPath expression could \& select a set of elements. Without it, getElement() returns the first \& element matching the given XPath. \& \& The XPath expression applies in the current context, and not always \& in the whole document (see currentContext()). However, if the \& reference of a previously selected element is provided as a third \& argument, the given element is used as the context. \& \& Position indicators start at 0 just like in Perl tables (and some \& other programming languages). \& \& Example: \& \& my $p = $doc\->getElement(\*(Aq//table:table\*(Aq, 0) \& \& indicates an element containing the first table of a text document \& or first sheet of a spreadsheet. \& \& Positions can also be counted backwards from the end by giving \& negative values, i.e. position \-1 being the last element. Thus: \& \& my $h = $doc\->getElement(\*(Aq//text:h\*(Aq, \-2); \& \& indicates the second\-last header of a text document. \& \& Note: None of the two examples above should be used in a real \& application, knowing that the ::Text module provides getTable() and \& getHeading() that do the job without XPath coding. \& \& When successful, this method ensures that the returned object is \& indeed an element and not another type of node (e.g. attribute, \& text, comment, etc.). Such an object is never a printable text; it\*(Aqs \& either a text container (whose content may be extracted using \& getText() or getFlatText()) or a non\-text element (such as a style, \& a font declaration, a variable field, a document properties container, \& etc). \& \& Limit: getElement() doesn\*(Aqt implement the full XPath specification, \& while it supports a large subset (see the XML::Twig documentation for \& details about the current XPath coverage). .Ve .PP \fIgetElementByIdentifier(id [, options])\fR .IX Subsection "getElementByIdentifier(id [, options])" .PP .Vb 2 \& Returns an element according to the given identifier, if any, or undef \& otherwise. \& \& Note that, according to the ODF 1.1 standard, some elements have \& identifiers (i.e. text:id attributes), while most haven\*(Aqt, so \& this method can\*(Aqt work with any object. \& \& Allowed options are: \& \& tag => restricts the search to a given element tag \& \& context => restricts the search to a given context \& \& Example: \& \& $section = $doc\->getElement(\*(Aq//text:section\*(Aq, 0); \& $note = $doc\->getElementByIdentifier( \& "id004", \& tag => \*(Aqtext:note\*(Aq, \& context => $section \& ); \& \& This sequence selects the note (i.e. footnote or endnote) identified by \& "id004" if such a note appear in the first section of the document. \& Without the \*(Aqcontext\*(Aq option, the search space would be the current \& context (that is the whole document by default). Without the \*(Aqtag\*(Aq \& option, the first object that owns the given identifier is selected, \& whatever its tag. \& \& See also getIdentifier(), setIdentifier(), identifier(). .Ve .PP \fIgetElementList(path [, context])\fR .IX Subsection "getElementList(path [, context])" .PP .Vb 1 \& Returns a list of all elements at a specified path. \& \& Example: \& \& my @ref_summary = $doc\->getElementList(\*(Aq//text:h\*(Aq); \& \& The above example returns a table containing all header elements of \& a text document. \& \& The path can of course be a more complex XPath expression \& stipulating, for example, a selection of attribute values. In most \& cases, you should avoid complicating things unnecessarily \& (especially in Text, Image and Styles modules), as there are methods \& for searching by element type, attribute and content which are much \& easier to use and avoid the need to supply XPath expressions. \& \& An optional context argument may be provided in order to restrict the \& search space. \& \& Note: the returned list contains elements in the sense of getElement() \& and not a list of element contents. .Ve .PP \fIgetFirstTextRun(path, position)\fR .IX Subsection "getFirstTextRun(path, position)" .PP \fIgetFirstTextRun(element)\fR .IX Subsection "getFirstTextRun(element)" .PP .Vb 5 \& Returns the first text segment of an element whose text content is \& segmented due to one or more child elements. In other words, returns \& the beginning of the text content up to the first child element, if \& any. If the given element just contains flat text, without any child \& element, returns the whole text, just like getText() introduced below. .Ve .PP \fIgetFlatText(path, position)\fR .IX Subsection "getFlatText(path, position)" .PP \fIgetFlatText(element)\fR .IX Subsection "getFlatText(element)" .PP .Vb 3 \& Like getText() below, but without rendering of possible tab stops, \& line breaks, repeated spaces, or any other markup. The returned text \& is just a decoded flat string. .Ve .PP \fIgetFrameElement(name/number)\fR .IX Subsection "getFrameElement(name/number)" .PP .Vb 2 \& Selects the frame identified by the given name, or by the given order \& number in the document context. .Ve .PP \fIgetIdentifier(path, pos)\fR .IX Subsection "getIdentifier(path, pos)" .PP \fIgetIdentifier(element)\fR .IX Subsection "getIdentifier(element)" .PP .Vb 1 \& Returns the identifier (text:id) of the given element, if any. \& \& See also identifier(), setIdentifier(), selectElementByIdentifier(). .Ve .PP \fIgetNodeByXPath(xpath_expression)\fR .IX Subsection "getNodeByXPath(xpath_expression)" .PP \fIgetNodeByXPath(xpath_expression, context)\fR .IX Subsection "getNodeByXPath(xpath_expression, context)" .PP \fIgetNodeByXPath(context, xpath_expression)\fR .IX Subsection "getNodeByXPath(context, xpath_expression)" .PP .Vb 6 \& A low\-level method which returns the node corresponding to the given \& XPath expression, if it exists in the document. This method (which \& gives unrestricted access to the entire content of a document) is \& designed for use with the unexpected. You will obviously need to be \& familiar with XPath syntax (not documented here) as well as \& OpenDocument structure. See also selectNodesByXPath(). .Ve .PP \fIgetObjectCoordinates(object)\fR .IX Subsection "getObjectCoordinates(object)" .PP .Vb 3 \& Returns the coordinates (X, Y) of the target object, if any. This \& method makes sense with "positioned" objects, i.e. with frames and \& frame\-like objects (images, text boxes). \& \& In an array context, the coordinates are returned as two distinct \& strings (horizontal, then vertical position). In a scalar context, \& the values are returned in a single string, and separated by a comma. \& \& See createFrameElement() for details about the coordinates and size \& units and notation. .Ve .PP \fIgetObjectDescription(object)\fR .IX Subsection "getObjectDescription(object)" .PP .Vb 3 \& Returns the litteral description of a visible object. This method \& makes sense for frames or frame\-like objects (such as images or \& text boxes). .Ve .PP \fIgetObjectName(element)\fR .IX Subsection "getObjectName(element)" .PP .Vb 1 \& Returns the name of the given element, if any. .Ve .PP \fIgetObjectSize(object)\fR .IX Subsection "getObjectSize(object)" .PP .Vb 2 \& Returns the size of the given object, if any. This method works with \& frames and other frame\-based objects, such as images and text boxes. \& \& In the returned data, the width comes first, followed by the height. \& \& The size is returned in the same way as the coordinates with \& getObjectCoordinates(). .Ve .PP \fI\fIgetPartName()\fI\fR .IX Subsection "getPartName()" .PP .Vb 2 \& Returns the name of the document part, i.e. \*(Aqcontent\*(Aq, \*(Aqstyles\*(Aq, \*(Aqmeta\*(Aq, \& and so on. .Ve .PP \fI\fIgetRoot()\fI\fR .IX Subsection "getRoot()" .PP .Vb 3 \& Returns the absolute root element of the document. The root element \& contains any other visible or non visible object, including the \& document body (see getBody) and style definitions. .Ve .PP \fIgetText(path, position)\fR .IX Subsection "getText(path, position)" .PP \fIgetText(element)\fR .IX Subsection "getText(element)" .PP .Vb 3 \& Returns text in the local character set, possibly UTF\-8 decoded, \& contained in the element given as an argument (by path/position or \& by reference). See also getFlatText(). \& \& Two equivalent examples: \& \& # version 1 \& \& my $element = $doc\->getElement(\*(Aq//text:p\*(Aq, 4); \& \& my $text = $doc\->getText($element); \& \& # version 2 \& \& my $text = $doc\->getText(\*(Aq//text:p\*(Aq, 4); \& \& Version 2 is better if the only aim is to get the text from \& paragraph 4. Version 1 is better, however, if during the course of \& the program you want to perform other operations on the same \& paragraph. Giving an element\*(Aqs reference will mean avoiding element \& handling methods having to recalculate a reference from the XPath \& path. .Ve .PP \fIgetTextList(path)\fR .IX Subsection "getTextList(path)" .PP .Vb 1 \& Returns text from all elements in the specified path. \& \& Example: \& \& my $summary = $doc\->getTextList(\*(Aq//text:h\*(Aq); \& \& my $report = $doc\->getTextList(\*(Aq//text:span\*(Aq); \& \& The $summary variable contains a concatenation of all headers. \& $report contains all the words or character strings that "stand out" \& which the user has designated by their context, e.g. words in \& italics in a non\-italic paragraph. \& \& In a list context, the returned data is a table, each of whose \& elements contains the text of an XML element. In a scalar context \& (as in our two examples), the returned value is a unique piece of \& editable text and each element\*(Aqs content is separated from that of \& the following element by a line feed. .Ve .PP \fIgetTextNodes(context [, filter])\fR .IX Subsection "getTextNodes(context [, filter])" .PP .Vb 6 \& Returns the text nodes belonging (at any level) to the given context \& element. So\-called text nodes are low\-level text runs, without \& attributes, that populate text containers such as paragraphs, knowing \& that a paragraph may contain one or more text nodes. For an example, \& as soon as a bookmark is put within a pararaph, there is (at least) one \& text node before the bookmark and another one after the bookmark. \& \& The textnodes are returned as a list in the order of the context. \& \& Note that a text node is not an element, but that every text node in \& a regular document is a child of a text element (generally a paragraph, \& a heading or a text span). So, the node\-based parent() method may be \& used to get the element that contains a given text node. \& \& The second argument (optional) specifies a search filter. If it\*(Aqs \& provided, only the matching text nodes are returned. \& \& The example below uses getTextNodes() in order to count the text nodes \& that contain "foo" and that belong to elements whose style is "bar" in \& the whole document body (beware, this examples uses methods which are \& introduced in the OpenOffice::OODoc::Text manual chapter): \& \& my $context = $doc\->getBody; \& my @list = (); \& foreach my $tn ($doc\->getTextNodes($context, "foo")) { \& my $style = $doc\->getAttribute \& ($tn\->parent, \*(Aqstyle name\*(Aq); \& next unless $style; \& push @list, $tn if $style eq "bar"; \& } .Ve .PP \fIgetUserField(name [, context])\fR .IX Subsection "getUserField(name [, context])" .PP .Vb 2 \& Returns the element (if defined) representing a user\-defined field, \& and corresponding to the given name. See also userFieldValue(). \& \& By default, this method works with the first user field declaration \& matching the given name in the whole document. However, if the calling \& object is a \*(Aqstyles\*(Aq document part, the search is restricted to a given \& context (provided through an optional 2nd argument) or to the current \& context. This feature allows the applications to look for user fields \& whose declarations are associated to page styles. .Ve .PP \fIgetUserFields([context])\fR .IX Subsection "getUserFields([context])" .PP .Vb 1 \& Returns the list of the declared user\-defined fields. \& \& The example below prints the names of all the user\-defined fields: \& \& foreach my $field ($doc\->getUserFields) \& { \& print $doc\->getObjectName($field); \& } \& \& By default, this method returns all the user fields at the document \& level. However, if the active document part is \*(Aqstyles\*(Aq, the search is \& restricted to a given context (provided through an optional 2nd \& argument) or to the current context. This feature allows the \& applications to look for user fields whose declarations are associated \& to page styles. .Ve .PP \fIgetVariable(name)\fR .IX Subsection "getVariable(name)" .PP .Vb 1 \& Returns the user\-defined variable identified by the given name. \& \& [Contribution by Andrew Layton] .Ve .PP \fI\fIgetVariableElement()\fI\fR .IX Subsection "getVariableElement()" .PP .Vb 1 \& See getVariable(). .Ve .PP \fIgetXMLContent([filehandle])\fR .IX Subsection "getXMLContent([filehandle])" .PP .Vb 1 \& Without argument, returns a document\*(Aqs entire XML content. \& \& Exports the entire XML content of the current member to a flat file, \& if a file handle is provided. \& \& Note: the exported data are UTF8\-encoded. \& \& Example: \& \& open my $fh, ">:utf8", "myfile.xml"; \& $doc\->getXMLContent($fh); \& close $fh; \& \& Synonym: exportXMLContent() .Ve .PP \fIgetXPathValue(xpath_expression)\fR .IX Subsection "getXPathValue(xpath_expression)" .PP \fIgetXPathValue(context, xpath_expression)\fR .IX Subsection "getXPathValue(context, xpath_expression)" .PP \fIgetXPathValue(xpath_expression, context)\fR .IX Subsection "getXPathValue(xpath_expression, context)" .PP .Vb 3 \& A low\-level method which allows direct access to the value \& corresponding to the given XPath expression in a document. Character \& decoding is handled in the same way as with getText. \& \& Example: \& \& $expression = \*(Aq//office:automatic\-styles\*(Aq . \& \*(Aq/style:style\*(Aq . \& \*(Aq[@style:style\-name="P1"]\*(Aq . \& \*(Aq/@style:parent\-style\-name\*(Aq; \& \& print $doc\->getXPathValue($expression); \& \& This sequence displays the name of the parent style of automatic \& style "P1" (if it exists within the document). Remember that more \& simple methods in Text and/or Styles modules would indeed produce \& the same result. \& \& The optional element reference "context" can be given as an argument \& either in first or second place. In this case, the search is limited \& to the section of the document tree below this given element. The \& default search area is the entire document. \& \& Just as with other methods which require XPath paths, this one is \& primarily for internal use. It should not be used by the majority of \& applications. .Ve .PP \fIidentifier(path, pos [, value])\fR .IX Subsection "identifier(path, pos [, value])" .PP \fIidentifier(element [, value])\fR .IX Subsection "identifier(element [, value])" .PP .Vb 1 \& Gets or sets the identifier of the given element. \& \& If the value argument is not provided, does the same as getIdentifier(). \& If provided, the value argument replaces the previous element identifier \& or creates it if it was not set. \& \& This method can change the identifier, but can\*(Aqt remove it, unlike \& setIdentifier(). \& \& See also getIdentifier(), setIdentifier(), getElementByIdentifier(). .Ve .PP \fIinsertElement(path, position, name/xml [, options])\fR .IX Subsection "insertElement(path, position, name/xml [, options])" .PP \fIinsertElement(element, name/xml [, options])\fR .IX Subsection "insertElement(element, name/xml [, options])" .PP .Vb 2 \& Inserts a new element before or after the element specified by \& [path, position] or by reference. \& \& If the "name" argument is a literal, a new element with the name \& given is created and then inserted. If the same argument is a \& reference to an existing element, this element is then simply \& inserted at the position indicated. This method is useful either for \& adding new elements or for copying elements from one document to \& another or from one position to another within the same document. \& \& The position option allows you to choose the insertion point of the \& new element. Possible values are "before", "after" and "within" (the \& default is "before"). \& \& If "position" is set to "within", the new element is inserted within \& the text of the target element, so an additional "offset" option (i.e. \& a numeric position in the string) is required. \& \& However, for insertion within a text container, setChildElement(), \& described later, is much more powerful. \& \& Other options are: \& \& text => "text of element" \& \& attributes => $attributes \& \& The "attributes" option is itself a hash reference containing one or \& more attributes in the form [name => value] as in appendElement. \& \& When successful, this method returns the inserted element\*(Aqs \& reference (else undef). \& \& Example: \& \& my $attributes = \& { \& \*(Aqtext:style\-name\*(Aq => \*(AqHeading 2\*(Aq, \& \*(Aqtext:level\*(Aq => \*(Aq2\*(Aq \& }; \& $doc\->insertElement \& ( \& \*(Aq//text:p\*(Aq, 4, \*(Aqtext:h\*(Aq, \& position => \*(Aqafter\*(Aq, \& text => \*(AqNew section\*(Aq, \& attribute => $attributes \& ); \& \& This sequence (in a text document) inserts a level 2 header \& \*(AqNew section\*(Aq immediately after paragraph 4. \& \& The $name argument can be replaced by an existing element. In this \& case a new reference to the existing element is inserted, without \& creating a whole new element. In this way you can display an element \& at several locations or in several documents which is held in memory \& only once. See the appendElement section for the consequences of \& having multiple references to the same physical element. Better to \& use replicateElement to insert separate copies of an element. \& \& In the same conditions as in appendElement, the \*(Aqname\*(Aq argument can \& be replaced by an XML string which describes the element. \& \& Note: to add an element to the end of a document, it would obviously \& be better to use appendElement(), and to insert an element at a selected \& position within an existing element, see setChildElement(). .Ve .PP \fI\fIisOpenDocument()\fI\fR .IX Subsection "isOpenDocument()" .PP .Vb 4 \& Returns 1 (true) if the current document is an OASIS Open Document. \& To be used every time the application needs to know the format of \& the document, knowing that some differences between the two formats \& can\*(Aqt be completely hidden by the API. .Ve .PP \fIlineBreak\fR .IX Subsection "lineBreak" .PP .Vb 4 \& Returns a special line break element, available for insertion within \& an existing text element (knowing that "\en" is not recognized as a \& line break if stored "as is"). The returned element is free, so it \& could/should be inserted later within a text element. .Ve .PP \fImakeXPath(expression)\fR .IX Subsection "makeXPath(expression)" .PP \fImakeXPath(context, expression)\fR .IX Subsection "makeXPath(context, expression)" .PP .Vb 6 \& Low\-level method allowing the creation or direct modification \& without restriction (almost) of any document element. It allows \& "query" expressions in a language similar to XPath. If the given \& XPath expression crosses several levels of hierarchy, intermediate \& nodes can be created or modified "on the fly" by creating the \& necessary path which in turn creates the final node. \& \& Example: \& \& $doc\->makeXPath \& ( \& \*(Aq//office:body/text:p[4 @text:style\-name="Text body"]\*(Aq \& ); \& \& This "query" applies the "Text body" style to paragraph 4 in the \& body of the document. (In reality you will probably never use it \& because the setStyle method of the Text module would do the same \& thing much more simply.) \& \& If, as in the above example, a node is accompanied by a position \& indicator, it cannot be created but must simply act as a mandatory \& "passage". This method cannot therefore be used to create, for \& example, an Nth paragraph if there is already an N\-1. \& \& The only restrictions apply to namespaces which are given as \& prefixes to element and attribute names. They must be defined in the \& document i.e. conform to OpenDocument specifications. For the rest, \& this method allows the creation of almost anything anywhere within a \& document. Its use is reserved for OpenDocument XML specialists. \& \& In its second form, a context node can be given as the first \& argument. If present, the path is sought (and if necessary created) \& starting from its position. By default, the path begins from the \& root. \& \& The returned value is the final node\*(Aqs reference (found or created). \& \& The full "query language" syntax used in this method is not \& documented here. makeXPath is designed to act more as a base for \& other OpenOffice::OODoc methods than to be used in applications. .Ve .PP \fImoveElements(target_element, element_list)\fR .IX Subsection "moveElements(target_element, element_list)" .PP .Vb 1 \& Moves a list of existing elements to a new attachment. \& \& One more elements are cut from their previous place and appended \& as children of the target element. \& \& This method can be used to move elements from one place to another \& place in the same document, as well as from one document to another \& one (caution, the elements are moved, not copied). .Ve .PP \fInewTextNode(text)\fR .IX Subsection "newTextNode(text)" .PP .Vb 1 \& Creates a free text node (to be inserted later within a text element). \& \& A text node is a piece of flat text, without any attribute, that may be \& a part or the text content of an element. \& \& Note that it\*(Aqs a low level method for special uses; there are various \& text\-oriented methods in the API (mainly described is the ::Text manual \& page), and the explicit use of text nodes should be avoided. .Ve .PP \fIobjectName(element [, name])\fR .IX Subsection "objectName(element [, name])" .PP .Vb 2 \& Returns the name of the given element. Changes this name is a new name \& is provided as the 2nd argument. .Ve .PP \fI\fIodfLocaltime()\fI\fR .IX Subsection "odfLocaltime()" .PP .Vb 1 \& Class method. \& \& Converts the numeric time given in argument to an OpenOffice\-compliant \& date (ISO\-8601). The argument type is the same as for the standard \& Perl localtime() function, i.e. a number of seconds since the "epoch". \& It can be, for example, a value previously returned by a time() call. \& \& Without argument, returns the current local time in ISO\-8601 format. \& \& The result of this function can be used as is in order to set the \& value of an ODF\-compliant date\-time element or attribute. .Ve .PP \fI\fIodfTimelocal()\fI\fR .IX Subsection "odfTimelocal()" .PP .Vb 1 \& Class method. \& \& Translates an ODF\-formatted date (ISO\-8601) into a regular Perl \& numeric time format, i.e. a number of seconds since the "epoch". So, \& the returned value can be processed with any Perl date formatting or \& calculation function. \& \& Example: \& \& my $date_created = odfTimelocal($meta\->creation_date()); \& $lt = localtime($date_created); \& $elapsed = time() \- $date_created; \& print "This document has been created $date_created\en"; \& print "$elapsed seconds ago"; \& \& This sequence prints the creation date of a document in local time \& string format, then prints the number of seconds between the creation \& date and now. Note that the creation_date() method used here works \& with the meta\-data document part only (see OpenOffice::OODoc::Meta for \& details about this method). \& \& Note: This function requires the Time::Local Perl module. .Ve .PP \fIodfVersion([new_version])\fR .IX Subsection "odfVersion([new_version])" .PP .Vb 1 \& See openDocumentVersion() .Ve .PP \fIooLocaltime([$time_value])\fR .IX Subsection "ooLocaltime([$time_value])" .PP .Vb 1 \& Class method. \& \& See odfLocaltime() .Ve .PP \fIooTimelocal($oodate)\fR .IX Subsection "ooTimelocal($oodate)" .PP .Vb 1 \& Class method. \& \& See odfTimelocal() .Ve .PP \fIopenDocumentVersion([new_version])\fR .IX Subsection "openDocumentVersion([new_version])" .PP .Vb 3 \& Returns the version of the Open Document Format (ODF) in use in the \& current document. If an argument is provided, it\*(Aqs used to set a \& new version identifier. \& \& Beware, this method doesn\*(Aqt really check the conformance of the \& document to any version of the ODF standard. It just retrieves the \& value of the version number attribute as it has been set by the \& application which created or modified the document. \& \& If openDocumentVersion() is used to set a new version number \& declaration, the given value is not checked. So, this value could \& be the number of a real or future ODF version (1.0, 1.1, 1.2, etc), \& as well as any other arbitrary value (ex: 99, \-1, ...). .Ve .PP \fIraw_import(member, source)\fR .IX Subsection "raw_import(member, source)" .PP .Vb 9 \& Physically imports an external file into an OpenDocument archive \& associated with an XPath object, if it exists i.e. if the object was \& created using file or archive parameters. This method only transmits \& the command to the OODoc::File\*(Aqs raw_import method. Caution: it must \& not be used with an "active" element i.e. an XML member to which the \& current XPath object or another XPath object is already associated. \& Remember too that the import is not actually carried out by \& OODoc::File until a save and the imported data is therefore not \& immediately available. .Ve .PP \fIraw_export(member, target)\fR .IX Subsection "raw_export(member, target)" .PP .Vb 4 \& Physically exports a member from an OpenDocument archive associated \& with an XPath object, if it exists i.e. if the object was created \& using file or archive parameters. This method only transmits the \& command to the OODoc::File\*(Aqs raw_import method. .Ve .PP \fIremoveAttribute(path, position, attribute)\fR .IX Subsection "removeAttribute(path, position, attribute)" .PP \fIremoveAttribute(element, attribute)\fR .IX Subsection "removeAttribute(element, attribute)" .PP .Vb 4 \& Deletes the "attribute" attribute (if found) of the given element by \& [path, position] or by reference and returns "true". Has no physical \& effect and returns undef if the attribute has not been defined or if \& the element does not exist. .Ve .PP \fIremoveElement(path, position)\fR .IX Subsection "removeElement(path, position)" .PP \fIremoveElement(element)\fR .IX Subsection "removeElement(element)" .PP .Vb 3 \& Deletes the given element (if found) by [path, position] or by \& reference and returns "true". Returns undef if the element does not \& exist. .Ve .PP \fIremoveIdentifier(path, pos)\fR .IX Subsection "removeIdentifier(path, pos)" .PP \fIremoveIdentifier(element)\fR .IX Subsection "removeIdentifier(element)" .PP .Vb 1 \& Deletes the identifier attribute (\*(Aqtext:id\*(Aq) of the given element. \& \& Be careful, this method should be used in order to delete temporary \& element identifiers that don\*(Aqt comply with the ODF specification; \& remember that the identifier is mandatory for some elements. \& \& See also getIdentifier(), setIdentifier(), identifier(). .Ve .PP \fIreplaceElement(path, position, replacement [, options])\fR .IX Subsection "replaceElement(path, position, replacement [, options])" .PP \fIreplaceElement(old_element, new_element [, options])\fR .IX Subsection "replaceElement(old_element, new_element [, options])" .PP .Vb 3 \& Deletes the given element by [path, position] or by reference and \& inserts another element in its place, either from another location \& in the same document or from another document. \& \& A new element can be supplied under the same conditions as for \& insertElement. \& \& By default or by using the mode => \*(Aqcopy\*(Aq option, it is a copy of \& the new element which is inserted. With the mode => \*(Aqreference\*(Aq \& option, it is only a reference which is inserted. See the section on \& appendElement for comments on the subject of multiple references to \& a single physical element. .Ve .PP \fIreplicateElement(original_element, position_object [, options]])\fR .IX Subsection "replicateElement(original_element, position_object [, options]])" .PP .Vb 3 \& Makes a copy of the first given element and inserts it into the \& current document at a position which depends on the second argument \& and an optional parameter. \& \& If the second argument is an existing object in the document, then \& the copy is inserted according to an optional \*(Aqposition\*(Aq parameter: \& \& \- if no \*(Aqposition\*(Aq option is provided, then the copy is appended \& as the last child of the position object; \& \& \- if \*(Aqposition\*(Aq => \*(Aqbefore\*(Aq or \*(Aqafter\*(Aq, then the copy is inserted at \& the same hierarchical level as the position object, according to the \& same logic as for insertElement(). \& \& If the second argument is not an object, but simply \*(Aqend\*(Aq, then the \& new element is appended as the very last child of the physical root \& of the document. See getRoot(). This option should generally be \& avoided. \& \& If the second argument is given as \*(Aqbody\*(Aq, then the new element \& is appended at the end of the document body (see getBody), as it was \& created through appendElement(). \& \& Example: \& \& my $template = $doc_source\->selectElementByAttribute \& ( \& \*(Aq//style::style\*(Aq, \& \*(Aqstyle:name\*(Aq, \& \*(AqText body\*(Aq \& ); \& my $position = $doc_target\->getElement \& (\*(Aq//office:styles\*(Aq, 0); \& $doc_target\->replicateElement($template, $position); \& \& This sequence adds a style \*(AqText body\*(Aq to the style set of $doc_target \& which copies exactly the style of the same name in $doc_source. \& Obviously, the section of code dealing with the search for the element \& to copy and its position is the most laborious. (In a real application, \& thanks to OODoc::Styles, a more user\-friendly coding would be allowed \& for style replication.) \& \& This method creates a new element which is an exact copy of the given \& element, but which is physically separate from it. \& \& This method is slower than simply modifying an existing element or \& inserting an element reference. \& \& If the user needs only a "free" copy of the element (out of the \& document structure, to be later attached), the XML::Twig::Elt copy() \& method should be preferred: \& \& my $new_element = $old_element\->copy; .Ve .PP \fI\fIresetCurrentContext()\fI\fR .IX Subsection "resetCurrentContext()" .PP .Vb 2 \& Resets the search context to its default value, which is the root of \& the document. See currentContext(). .Ve .PP \fIsave([filename|filehandle])\fR .IX Subsection "save([filename|filehandle])" .PP .Vb 5 \& Saves the content of the current document through a physical \& output, that is either a regular file specified by path/name, or \& an open, application\-provided IO::Handle. If no argument is \& provided, the document which had been used as the source (if any) \& is used as the default target. \& \& Technically, as soon as the document container is a regular ODF \& file, this method is a stub for the save() method of the associated \& OpenOffice::OODoc::File object, so all the related explanations and \& recommendations given in the OpenOffice::OODoc::File manual chapter \& apply. So, for example, be careful if the target is an open IO::Handle \& instead of a file path/name. \& \& The behaviour of this method depends on the way the current \& OpenOffice::OODoc::XPath object has been created. \& \& If the document is explicitly linked (through the \*(Aqfile\*(Aq option \& of it\*(Aqs constructor) to a regular OOo or OpenDocument file, the \& document is saved either in the source file, or (if a filename \& is provided as an argument) in a new file. \& \& If the document is linked to the same file interface as one or \& more other OpenOffice::OODoc::XPath objects, the behaviour is \& the same as in the previous case, but all the changes made by \& all the linked objects are automatically saved in the target \& file. Example: \& \& my $content = odfXPath \& ( \& file => \*(Aqsource.odt\*(Aq, \& part => \*(Aqcontent\*(Aq \& ); \& my $styles = odfXPath \& ( \& container => $content, \& part => \*(Aqstyles\*(Aq \& ) \& my $meta = odfXPath \& ( \& container => $content, \& part => \*(Aqmeta\*(Aq \& ); \& # ... a lot of content processing \& # ... a lot of style processing \& # ... a lot of metadata processing \& $content\->save(\*(Aqtarget.odt\*(Aq); \& \& At the end of the sequence above, all the changes made through \& the $content, $styles and $meta objects are saved in \*(Aqtarget.odt\*(Aq \& because these objects share a common file interface. Note that \& in such a situation, the save() method can be issued from anyone \& of the objects sharing the file interface (i.e. $content\->save \& could be replaced by $styles\->save or $meta\->save). \& \& However, any XML part (content, styles, meta, ...) whose \& \*(Aqread_only\*(Aq property is set to "true" is not saved. In the example \& above, if, say, the $meta object is created (through odfXPath()) \& with a "read_only" option set to "true", only $content and $styles \& are really saved by the last instruction. \& \& If the document is not associated with a regular OpenDocument \& compressed file (used through an OODoc::File object), it\*(Aqs saved \& as "flat XML" to the given file. In such a situation, if the file name \& is not provided, the source XML file (if any) is used as the target. \& If the file is "flat XML", OODoc::XPath really effects the physical \& output, without using any OODoc::File connector. \& \& Note: if you need to save a document as flat XML while it\*(Aqs associated \& with an OpenDocument file, you should use exportXMLContent() with an \& application\-provided file handle. .Ve .PP \fIselectChildElementByName(path, position [, filter])\fR .IX Subsection "selectChildElementByName(path, position [, filter])" .PP \fIselectChildElementByName(element [, filter])\fR .IX Subsection "selectChildElementByName(element [, filter])" .PP .Vb 3 \& Returns the first (or only) element whose name matches "filter" from \& within the child elements of the given element indicated by [path, \& position] or by reference. \& \& "filter" is taken to be a regular expression. If several values \& match the filter, the first of these is returned (in the XML\*(Aqs \& physical order which is not necessarily the logical order of the \& document). See the comments about selectElementByAttribute if \& wanting to select an exact name. \& \& Returns undef if no elements match the condition. \& \& Returns the first (or only) child (if there are more than one) \& without anything else if no filter is given or if the filter uses \& wildcards (".*"). .Ve .PP \fIselectChildElementsByName(path, position [, filter])\fR .IX Subsection "selectChildElementsByName(path, position [, filter])" .PP \fIselectChildElementsByName(element [, filter])\fR .IX Subsection "selectChildElementsByName(element [, filter])" .PP .Vb 2 \& Like selectChildElementByName, but returns a list of all elements \& which match the condition. \& \& Example: \& \& my @search_words = \& $doc\->selectChildElementsByName \& (\*(Aq//text:p\*(Aq, 4, \*(Aqtext:span\*(Aq); \& \& returns a list of elements from paragraph 4 which correspond to text \& which has particular attributes which distinguish it from the rest \& of the paragraph (colour, font, etc.) .Ve .PP \fIselectElements([context,] path, filter)\fR .IX Subsection "selectElements([context,] path, filter)" .PP \fIselectElements([context,] path, filter, replacement)\fR .IX Subsection "selectElements([context,] path, filter, replacement)" .PP \fIselectElements([context,] path, filter, action [, arg1, ...])\fR .IX Subsection "selectElements([context,] path, filter, action [, arg1, ...])" .PP .Vb 5 \& Returns a list of elements corresponding to a given XPath path and \& whose text matches the filter (regular expression). The "context" \& argument, if given, is an element reference which limits the search \& to its own child elements. The search is carried out in the entire \& document by default. \& \& An element is selected if the search string is found in its own text \& or in the text of any element descended from it. E.g. An image \& element (draw:image) can be selected from the value of its attached \& "description" field. \& \& You can replace all strings matching the search criteria with the \& \*(Aqreplacement\*(Aq string, on the fly, if the latter is given as an \& argument after the filter. \& \& Lastly, instead of a replacement string, you can pass a subroutine\*(Aqs \& reference which will run (in call back mode) each time the search \& string is matched. If this subroutine returns a defined value, this \& value is used as the replacement string. The subroutine will \& automatically receive the rest of the arguments, in this order: \& \& Caution: this method can\*(Aqt retrieve a character string which is \& split into more than one text element or text span. So, for example, \& it will never retrieve "My String" as long as "My" and "String" are \& presented with different styles, even if the two parts of the string \& belong to the same paragraph. \& \& If, as is generally the case, you are working exclusively with text \& elements (paragraphs, headers, etc.), you would be better to use \& selectElementsByContent() of the Text module which is easier to use \& and does not require an XPath expression. \& \& Here is an example which returns the list of images whose \& descriptors contain the word "landscape" and displays the name of \& each selected image: \& \& sub printMessage \& { \& my $doc = shift; \& my $element = shift; \& my $image = $element\->parentNode; \& print "Name: " . $image\->find(\*(Aq@draw:name\*(Aq) . "\en"; \& } \& my @list = $doc\->selectElements \& ( \& \*(Aq//draw:image/svg:desc\*(Aq, \& \*(Aqlandscape\*(Aq, \& \e&printMessage, \& $doc \& ); \& \& Never use this example of code in a real application as it is both \& purely for demonstration and unnecessarily complex. You can perform \& the same operation much more simply using the OODoc::Image module. .Ve .PP \fIselectElementByAttribute(path, attribute [, value [, context [, pos]]])\fR .IX Subsection "selectElementByAttribute(path, attribute [, value [, context [, pos]]])" .PP .Vb 4 \& Like selectElementsByAttribute in a scalar context. By default, returns \& the first element at the given path which has the given attribute \& containing the given value. If the value is omitted, then returns the \& first (or only) element that owns the attribute whatever the value. \& \& The context optional argument allows one to restrict the search space to \& a given container. The last optional argument, if set, is a positive \& integer that specifies the index of the required element if more than \& one element match the other conditions (beware: if the specified \& position is out of range, the result is undef). \& \& The following example (that apply with the "styles" part of an ODF \& document) prints a message if the "Time New Roman" font face is \& declared: \& \& print "The Time New Roman font is defined !" \& if $styles\->selectElementByAttribute ( \& \*(Aqstyle:font\-face\*(Aq, \& \*(Aqstyle:name\*(Aq, \& "Times New Roman" \& ); \& \& Returns undef if no element matches the conditions. \& \& See also selectElementsByAttribute(). .Ve .PP \fIselectElementsByAttribute(path, attribute [, value [, context]])\fR .IX Subsection "selectElementsByAttribute(path, attribute [, value [, context]])" .PP .Vb 3 \& Like selectElementByAttribute(), but for an array context. Returns \& all the elements that match the path/attribute/value/context conditions \& as a list. \& \& The following example selects a document section whose name is \& "Foreword" then selects the list of all the level 3 headings in this \& section (note that $section is used as the optional context argument \& in the second instruction): \& \& my $section = $doc\->selectElementByAttribute \& (\*(Aqtext:section\*(Aq, \*(Aqtext:name\*(Aq, "Foreword"); \& my @headings3 = \& $doc\->selectElementsByAttribute \& (\*(Aqtext:h\*(Aq, \*(Aqtext:outline\-level\*(Aq, 3, $section); \& \& (But remember that the same result could be got without knowledge of the \& XML tags and attributes using more user\-friendly methods introduced in \& other manual chapters !) \& \& See also selectElementByAttribute(). .Ve .PP \fIselectFrameElementByName(name)\fR .IX Subsection "selectFrameElementByName(name)" .PP .Vb 3 \& Selects the first frame element whose name is exactly the given \& argument. A frame is an OpenDocument container which can host a \& rectangular object, such as an image or a text box. .Ve .PP \fIselectNodesByXPath(xpath_expression)\fR .IX Subsection "selectNodesByXPath(xpath_expression)" .PP .Vb 3 \& This low\-level method returns a list of nodes (which are not \& necessarily elements) which match the give XPath expression. See \& getNodeByXPath() for options and comments. .Ve .PP \fIsetAttribute(path, position, attribute, value)\fR .IX Subsection "setAttribute(path, position, attribute, value)" .PP \fIsetAttribute(element, attribute, value)\fR .IX Subsection "setAttribute(element, attribute, value)" .PP .Vb 1 \& Modifies or adds an attribute to an element. \& \& The element is indicated by reference or by [path, position]. \& \& The following arguments are the attribute name and the value. \& \& If the name is provided without namespace prefix, it\*(Aqs automatically \& concatenated to the element\*(Aqs namespace prefix. Every space in the \& attribute name, if any, is automatically replaced by a \*(Aq\-\*(Aq. \& \& If the value is undef, the corresponding attribute is deleted if it \& exists in the element; nothing is done otherwise. .Ve .PP \fIsetAttributes(path, position, attributes_table)\fR .IX Subsection "setAttributes(path, position, attributes_table)" .PP \fIsetAttributes(element, attributes_table)\fR .IX Subsection "setAttributes(element, attributes_table)" .PP .Vb 1 \& Modifies or adds one or more attributes to an element. \& \& The element is indicated by reference or by [path, position]. \& \& The list of attributes is given in the form of a hash name => value. \& \& Example: \& \& my $h = $doc\->getElement(\*(Aq//text:h\*(Aq, 12); \& $doc\->setAttributes( \& $h, \& \*(Aqtext:style\-name\*(Aq => \*(AqMy Header\*(Aq, \& \*(Aqtext:level\*(Aq => 3 \& ); \& \& This sequence gives the \*(AqMy Header\*(Aq style and level 3 to the 13th \& "header" element in the document. \& \& Any attribute name provided without namespace prefix is automatically \& concatenated with the namespace prefix of the target element. So, the \& "text:" prefix could have been omitted in the attribute hash of the \& example above. In addition, every space in an attribute name is \& automatically replaced by a \*(Aq\-\*(Aq. So the code below produces the same \& result as the previous example: \& \& my $h = $doc\->getElement(\*(Aq//text:h\*(Aq, 12); \& $doc\->setAttributes( \& $h, \& \*(Aqstyle name\*(Aq => \*(AqMy Header\*(Aq, \& \*(Aqlevel\*(Aq => 3 \& ); \& \& An attribute provided as undef is deleted, if it exists. .Ve .PP \fIsetChildElement(context, tag/element [, options])\fR .IX Subsection "setChildElement(context, tag/element [, options])" .PP .Vb 5 \& Creates a new child element within the text content of an existing one. \& The context element may be provided like with insertElement(), either \& by [path, position] or directly as the 1st argument. The next argument \& is the XML tag of the element to be created, or an existing free \& element. \& \& The given context may be any element, including the whole document body; \& however, it should be a simple text container in most cases. \& \& If the provided tag doesn\*(Aqt include a namespace prefix, it\*(Aqs \& automatically concatenated with the namespace prefix of the context \& element (provided as 1st argument). In addition, every space (" ") is \& regarded as a "\-". For example, knowing that the ODF names of a line \& break and a tab stop are respectively \*(Aqtext:line\-break\*(Aq and \*(Aqtext:tab\*(Aq, \& they may be specified as \*(Aqline break\*(Aq and \*(Aqtab\*(Aq when they are inserted \& in a regular text paragraph (that is their right place). \& \& For alternative and very specific purposes, the tag argument may be \& replaced by a function reference. If so, the corresponding application\- \& provided function will be triggered with the following arguments: the \& containing document, a text node, a position, and possibly a string \& (this last argument will be provided if setChildElement() is called with \& a \*(Aqreplace\*(Aq, \*(Aqafter\*(Aq, \*(Aqbefore\*(Aq or \*(Aqcapture\*(Aq argument introduced below \& and will contain the matching substring). The application\-provided \& function is supposed to insert one or more contiguous new elements in \& the text node at the given position (optionally using the given \& substring); it must return an element. However, most users may safely \& forget this feature... \& \& Allowed options are \& \& attributes => attribute/value hash for the new element \& text => text content for the new element \& offset => position \& after => search string (regexp) \& before => search string (regexp) \& replace => search string (regexp) \& capture => search string (regexp) \& way => search way (\*(Aqforward\*(Aq or \*(Aqbackward\*(Aq) \& start_mark => element \& end_mark => element \& \& Some of them are mutually exclusive. They work according to the \& following logic. \& \& By default, the new element is created without text and attributes. \& However, an initial content may be provided through a \*(Aqtext\*(Aq optional \& parameter. In addition, a \*(Aqattributes\*(Aq option allows one to provide a set \& of attributes for the new element as a hash reference; note that every \& attribute name provided without namespace prefix is automatically \& concatenated with the same namespace prefix as the given element name. \& \& The child element may be inserted at the beginning, at the end, or at a \& position within the text content. In the last case, the position may be \& specified by a given numeric argument, or looked for according a given \& expression. \& \& By default, the new element is inserted at the beginning of the target \& element. An arbitrary other position may be specified with the \*(Aqoffset\*(Aq \& argument, that is either an integer (positive or negative) value, or one \& of the \*(Aqstart\*(Aq and \*(Aqend\*(Aq special indicators. If \*(Aqoffset\*(Aq is set to \& \*(Aqstart\*(Aq or \*(Aqend\*(Aq, the new element is inserted at the start or at the \& end, and the other position options are ignored. If \*(Aqoffset\*(Aq is a \& negative integer, the position is counted backward from the end. \& Caution: if the text of the target container includes tab stops and/or \& multiple contiguous spaces, the effective offset will be larger than \& the given one (because ODF tab stops and multiple spaces are special \& markup elements and not characters). \& \& Whatever the value of \*(Aqoffset\*(Aq, a \*(Aqway\*(Aq option, whose possible values \& are \*(Aqforward\*(Aq (the default) or \*(Aqbackward\*(Aq, specifies the search way. \& If \*(Aqoffset\*(Aq is negative, the \*(Aqway\*(Aq option is ignored because the \& way is always backward. If \*(Aqoffset\*(Aq is positive and \*(Aqway\*(Aq is \*(Aqbackward\*(Aq, \& then the result is the same as if \*(Aqoffset\*(Aq was negative. If \*(Aqoffset\*(Aq \& is 0 or not set and \*(Aqway\*(Aq is \*(Aqbackward\*(Aq, then the search is done \& backward from the end. \& \& A search string may be provided instead of or in combination with an \& offset. If so, the insert point will depend on the position of the first \& substring that matches the given optional search expression (if any). \& The search expression may be provided through the \*(Aqafter\*(Aq, \*(Aqbefore\*(Aq, \& \*(Aqreplace\*(Aq or \*(Aqcapture\*(Aq option. An expression provided with \*(Aqafter\*(Aq or \& \*(Aqbefore\*(Aq means that the insert point is immediately after or before the \& first matching substring. If the search string is provided through \& \*(Aqreplace\*(Aq or \*(Aqcapture\*(Aq, the matching string will be replaced by the new \& element. If the option is \*(Aqreplace\*(Aq the matching string is just deleted \& while if \*(Aqcapture\*(Aq the same matching string is moved in the new element. \& Of course, these search string options are mutually exclusive; if more \& than one of them are wrongly set, only one is considered, and the \& priority order is \*(Aqafter\*(Aq, \*(Aqbefore\*(Aq, \*(Aqreplace\*(Aq, and \*(Aqcapture\*(Aq. If both \& \*(Aqcapture\*(Aq and \*(Aqtext\*(Aq are set, the result is the same as with \*(Aqreplace\*(Aq \& and \*(Aqtext\*(Aq. \& \& If the insertion point depends on a search string (i.e. if \*(Aqafter\*(Aq, \& \*(Aqbefore\*(Aq, \*(Aqreplace\*(Aq or \*(Aqcapture\*(Aq is used), it\*(Aqs selected according to \& the first match. However, it\*(Aqs possible to reverse the search way using \& the \*(Aqway\*(Aq option. In addition, the search area may be restricted by the \& \*(Aqoffset\*(Aq parameter: if \*(Aqoffset\*(Aq is used in combination with any search \& string option, it specifies the limit of the search area instead of \& a insertion point; if \*(Aqoffset\*(Aq is positive and \*(Aqway\*(Aq is \*(Aqforward\*(Aq (or \& not set), the search is done from \*(Aqoffset\*(Aq to the end; if \*(Aqoffset\*(Aq is \& negative or \*(Aqway\*(Aq is \*(Aqbackward\*(Aq, the search is done backward from the \& given offset to the beginning. \& \& The \*(Aqstart_mark\*(Aq optional parameter is a child element that already \& exists within the context element. If this parameter is set, it \& specifies that the search will start from the position of this child \& element and not from the beginning of the end of the context element. \& If the search way is forward, the insert point (in case of success) \& will be located after the start mark, but if the search way is backward \& the insert point will be before the start mark. And if an offset is \& provided, it\*(Aqs counted from the position of the start mark. \& \& Another existing child element may be used in order to restrict the \& search area, through a \*(Aqend_mark\*(Aq parameter. If this parameter is set, \& no search will be done beyond it. If both \*(Aqstart_mark\*(Aq and \*(Aqend_mark\*(Aq \& are provided, the search will run from the first one to the second one \& Of course, if the start mark is located after the end mark, nothing \& will be done if the search way is not backward, and vice\-versa. \& \& The following example inserts a new \*(Aqtext:time\*(Aq element (i.e. an ODF \& time field) immediately after the first "Clock:" substring appearing \& between the 20th character and the end of a given paragraph (specified \& by the 1st argument). The new element will be a \*(Aqtext:time\*(Aq, knowing \& that the namespace prefix of a paragraph element (text:p) is "text". \& According to the given attributes, the field will display the current \& time increased by 15 minutes: \& \& $doc\->setChildElement( \& $paragraph, \*(Aqtime\*(Aq, \& offset => 20, \& after => "Clock:", \& attributes => { \& \*(Aqtime\-value\*(Aq => odfLocaltime() \& } \& ); \& \& The variant below creates a the same \*(Aqtime\*(Aq field after each occurrence \& of "Clock:" (probably not very useful, but the aim is to illustrate the \& use of \*(Aqstart_mark\*(Aq in order to ensure that every field but the first \& one will be inserted after the previous field): \& \& my $field = undef; \& while ( \& $field = $doc\->setChildElement( \& $paragraph, \*(Aqtime\*(Aq, \& after => "Clock:", \& start_mark => $field, \& attributes => { \& \*(Aqtime\-value\*(Aq => odfLocaltime() \& } \& ) {} \& \& Note that the loop body is empty; the start mark, which is undef at the \& first round, is then the previously inserted child element. \& Caution: without carefully designed offset and/or search option, such \& a construct may produce a long or infinite loop (until memory fault); \& in addition, the setChildElements() method (see below) is generally \& more appropriate for such repetitive element insertions. \& \& The next example creates a text span (i.e. a text area with a special \& character style) for the last "ODF" substring of a given paragraph: \& \& $doc\->setChildElement( \& $paragraph, \*(Aqspan\*(Aq, \& capture => "ODF", \& way => \*(Aqbackward\*(Aq \& attributes => { \& \*(Aqstyle\-name\*(Aq => "My Style" \& } \& ); \& \& These examples are shown to illustrate the general logic, not \& necessarily to be reproduced in real applications, knowing that \& setChildElement() is a common basis for more specialized methods \& (mainly introduced in the OODoc::Text man page). \& \& See also splitContent(). .Ve .PP \fIsetChildElements(context, tag/element [, options])\fR .IX Subsection "setChildElements(context, tag/element [, options])" .PP .Vb 2 \& Like setChildElement() but with a repetitive effect that depends on the \& options. \& \& If \*(Aqoffset\*(Aq is the only one option, it\*(Aqs used at a regular interval \& between insert points. If one of the search string options (\*(Aqafter\*(Aq, \& \*(Aqbefore\*(Aq, \*(Aqcapture\*(Aq, or \*(Aqreplace\*(Aq) is set, \*(Aqoffset\*(Aq is used once for all \& to exclude an area from the search space, and not as an interval between \& the new elements. The other options work like with setChildElement(). \& \& The example below inserts a line break after every ";" in a given \& paragraph (remember that an ODF line break is an element; it\*(Aqs neither \& an end of paragraph nor a "\en" character): \& \& $doc\->setChildElements( \& $paragraph, \*(Aqline break\*(Aq, \& after => ";" \& ); .Ve .PP \fIsetFlatText(path, position, text)\fR .IX Subsection "setFlatText(path, position, text)" .PP \fIsetFlatText(element, text)\fR .IX Subsection "setFlatText(element, text)" .PP .Vb 2 \& Like setText() described below, but without translation of "\et" \& and "\en". \& \& For exceptional use only. Allows, for example, the use of the OODoc \& API with non\-OpenDocument XML files. .Ve .PP \fIsetIdentifier(path, pos, value)\fR .IX Subsection "setIdentifier(path, pos, value)" .PP \fIsetIdentifier(element, value)\fR .IX Subsection "setIdentifier(element, value)" .PP .Vb 7 \& Sets (or resets) the identifier of the given element. The identifier is \& namely the \*(Aqtext:id\*(Aq attribute, that is allowed for some elements and \& not for other elements by the ODF standard. OpenOffice::OODoc allows it \& with any kind of element, and doesn\*(Aqt check its uniqueness, so it may be \& used with care. A non\-conformant element identifier is not an issue if, \& for example, it\*(Aqs removed before editing or processing the resulting \& documents through another application. \& \& This method removes the identifier if the value argument is undef; \& however the removeIdentifier() method produces the same result in a \& more self\-documented way). .Ve .PP \fIsetObjectCoordinates(object, coordinates)\fR .IX Subsection "setObjectCoordinates(object, coordinates)" .PP .Vb 3 \& Updates or creates the coordinates (X, Y) attributes of a visible \& object (ex: image, text box, frame). See createFrameElement() for the \& coordinates units and notation. .Ve .PP \fIsetObjectDescription(object, description)\fR .IX Subsection "setObjectDescription(object, description)" .PP .Vb 1 \& Updates or creates the litteral description of the given object. \& \& Should be used for frames, images or text boxes. Caution: the \& description is not the same as the printable content of a text \& box. .Ve .PP \fIsetObjectName(element, name)\fR .IX Subsection "setObjectName(element, name)" .PP .Vb 2 \& Sets or changes the name of the given element according to the given \& new name. Deletes the name if the given name is undef. .Ve .PP \fIsetObjectSize(object, size)\fR .IX Subsection "setObjectSize(object, size)" .PP .Vb 1 \& Updates or creates the width and height attributes of a given object. \& \& This method makes sense for visible, rectangular objects only, such \& as the frames, images or text boxes. \& \& See createFrameElement() for details about the size units and \& notation. .Ve .PP \fIsetRangeMark(type, identifier, parameters)\fR .IX Subsection "setRangeMark(type, identifier, parameters)" .PP .Vb 3 \& Creates a pair of corresponding delimiting markup elements in place, in \& order to set up an identified text range (such as a range bookmark, \& an index mark or a table of content mark). \& \& The first argument specifies the type of range; it\*(Aqs mandatory but its \& value is not checked. Examples of legal types are \*(Aqbookmark\*(Aq, \& \*(Aqtoc\-mark\*(Aq, \*(Aqalphabetical\-index\-mark\*(Aq. If the provided type doesn\*(Aqt \& contain a semicolon, it\*(Aqs automatically prefixed according to the \& content of the \*(Aqprefix\*(Aq parameter (whose default is \*(Aqtext\*(Aq). \& \& The identifier argument id mandatory; it\*(Aqs an arbitrary (preferently \& unique) identifier for the pair. While this identifier is generally \& invisible for the end\-user, it\*(Aqs sometimes an explicit name (for \& example in a range bookmark). \& \& The \*(Aqprefix\*(Aq optional parameter allows the applications to specify a \& particular XML prefix; the default prefix for range marks is \*(Aqtext\*(Aq. \& \& An arbitrary set of attributes may be provided as a hash through an \& optional \*(Aqattributes\*(Aq parameter. This hash will be processed according \& to the same logic as with the common setAttributes() method. \& \& The \*(Aqcontext\*(Aq optional parameter, if provided, specifies the element \& (which should be a text container, such as a paragraph, a heading or a \& text span) containing the text range to be delimited. However, if \& the covered text range is spread across two or more text containers, \& this parameter must not be set, and a separate \*(Aqcontext\*(Aq parameter must \& be provided for the start mark and the end mark (see below). \& \& If (and only if) the \*(Aqcontext\*(Aq parameter is set (meaning that the whole \& text content between the marks belongs to the same element), a \& \*(Aqcontent\*(Aq optional parameter allows one to provide an expression; if so, \& the setRangeMark() will look for the first substring that matches this \& expression in the target element, and in case of success the range marks \& will be inserted at the beginning and the end of this substring. The \& search space of the substring may be restricted using the \*(Aqoffset\*(Aq and \& \*(Aqway\*(Aq parameters, according to the same rules as setChildElement(). \& Note that the \*(Aqreplace\*(Aq, \*(Aqbefore\*(Aq and \*(Aqafter\*(Aq parameters don\*(Aqt apply \& with setRangeMark(). \& \& Unless \*(Aqcontext\*(Aq and \*(Aqcontent\*(Aq are defined, there are two mandatory \& parameters, namely \*(Aqstart\*(Aq and \*(Aqend\*(Aq; each one is a hash of parameters \& that apply to the start mark and the end mark, respectively. Each one \& allows the same options as the option hash of setChildElement(), i.e. \& \*(Aqoffset\*(Aq, \*(Aqbefore\*(Aq, \*(Aqafter\*(Aq, \*(Aqreplace\*(Aq and/or \*(Aqway\*(Aq as described above. \& Note that the \*(Aqstart\*(Aq and \*(Aqend\*(Aq structures are ignored as soon as \& the \*(Aqcontext\*(Aq and \*(Aqcontent\*(Aq parameters are set at the first level. \& \& In addition, if the start and end marks are not contained in the same \& text element, separate \*(Aqcontext\*(Aq parameters must be provided with each \& one of the \*(Aqstart\*(Aq hash and the \*(Aqend\*(Aq hash. However, if the \*(Aqend\*(Aq hash \& doesn\*(Aqt contain any \*(Aqcontext\*(Aq parameter, the end mark is supposed to \& be in the same container as the start mark. \& \& The method returns the new start and end marks as a list of elements \& in array context, or the start mark only in scalar context. \& In case of failure (due to wrong parameters), both are undef, knowing \& than setRangeMark() creates the full pair of marks or nothing. Note \& that the optional attributes (provided through the \*(Aqattributes\*(Aq \& parameter) are stored in the start mark element only. \& \& By default, nothing prevents the applications from creating a range mark \& whose start point is (temporarily or not) located after the end point, \& so introducing an inconsistency. However, it\*(Aqs possible to set a \*(Aqcheck\*(Aq \& boolean option; if this option is \*(Aqtrue\*(Aq, an order check is done and, if \& something is wrong, the range mark creation is cancelled and the method \& fails. On the other hand, as long as the application may ensure that it \& the start will always be set before the end, the order check should be \& avoided for performance reasons. \& \& Caution: The relative positions of the two marks are not checked, so \& nothing prevents the users from creating a range whose start point \& is (temporarily or not) located after the end point in the document. \& The applications should ensure that the \*(Aqstart\*(Aq and \*(Aqend\*(Aq options \& really specify two locations in the right order. \& \& The following instruction creates an index mark covering a \& text area within a single paragraph (previously selected); the range \& starts before the "abc" substring and ends after the "xyz" substring; \& the mark identifier is \*(Aqind1234\*(Aq. Nothing is done if one of these \& substrings is not present in the target element: \& \& $doc\->setRangeMark( \& \*(Aqalphabetical\-index\-mark\*(Aq, \*(Aqind1234\*(Aq, \& element => $paragraph, \& start => { before => "abc" }, \& end => { after => "xyz" } \& ); \& \& The next example creates a range bookmark (i.e. a bookmark covering \& a text area) that starts before the "abc" substring in a paragraph \& and ends at the end of another paragraph: \& \& $doc\->setRangeMark( \& \*(Aqbookmark\*(Aq, \*(Aqbm0001\*(Aq, \& start => { element => $p1, before => "abc" }, \& end => { element => $p2, offset => \*(Aqend\*(Aq } \& ); .Ve .PP \fIsetText(path, position, text)\fR .IX Subsection "setText(path, position, text)" .PP \fIsetText(element, text)\fR .IX Subsection "setText(element, text)" .PP .Vb 1 \& Uses the given text as the content of the given element. \& \& Any previous content (including formatting markup, bookmarks, \& notes, references, etc) is replaced by the given text. \& \& If the given text includes tab stops ("\et") or line breaks ("\en"), \& they are replaced by the appropriate OpenDocument tags. If this \& translation must be avoided, use setFlatText() instead. \& \& Note: The strings containing repeated whitespaces are not properly \& processed by default. A sequence of repeated spaces, whatever its \& length, is replaced by a single space in the target document. So \& \& $doc\->setText($p, "Begin End"); \& \& produces the same visible result as \& \& $doc\->setText($p, "Begin End"); \& \& It\*(Aqs possible to override this default behaviour using the \& \*(Aqmultiple_spaces\*(Aq document property. If \*(Aqmultiple_spaces\*(Aq is \& set to \*(Aqon\*(Aq, the repeated spaces in the example above are properly \& recorded. However, this optional feature is a the price of some \& other features and, above all, it have a negative impact on the \& performances (due to an additional processing of *every* space). \& Of course, a temporary activation of the \*(Aqmultiple_spaces\*(Aq \& feature is allowed, like in the following example, which sets \& a content including multiples whitespaces: \& \& $doc\->{\*(Aqmultiple_spaces\*(Aq} = \*(Aqon\*(Aq; \& $doc\->setText($p, "Begin End"); \& $doc\->{\*(Aqmultiple_spaces\*(Aq} = undef; \& \& See spaces() and extendText() for a workaround if you \& need to insert repeated spaces without using the \*(Aqmultiple_spaces\*(Aq \& property. .Ve .PP \fIsetUserFieldDeclaration(name [, options])\fR .IX Subsection "setUserFieldDeclaration(name [, options])" .PP .Vb 1 \& Creates a new user field declaration in the document. \& \& The optional parameter are: \& \& \*(Aqtype\*(Aq => data type (default \*(Aqstring\*(Aq) \& \& \*(Aqvalue\*(Aq => initial value (default "") \& \& \*(Aqcurrency\*(Aq => a 3\-letter currency code (ex: EUR, USD...) \& \& See also setTextField() in OpenOffice::OODoc::Text. .Ve .PP \fIspaces(length)\fR .IX Subsection "spaces(length)" .PP .Vb 6 \& Returns a special element, available for insertion within a text \& element, representing repeated contiguous blank spaces (knowing \& that repeated spaces can\*(Aqt be properly displayed by an OpenDocument\- \& compliant application if stored as a flat string). The returned \& element is free, so it could/should be inserted later within a text \& element. See extendText() for an example of use. .Ve .PP \fIsplitContent(path, pos, tag, expression [, attributes])\fR .IX Subsection "splitContent(path, pos, tag, expression [, attributes])" .PP \fIsplitContent(element, tag, expression [, attributes])\fR .IX Subsection "splitContent(element, tag, expression [, attributes])" .PP .Vb 2 \& Moves some parts of the text content of the given element and its \& descendants in new child elements. \& \& The tag argument specifies the XML tag of the child elements to be \& created. Unless this tag is provided with a namespace prefix (or more \& precisely unless it contains a semicolon), it\*(Aqs automatically \& concatenated with the namespace prefix of the host element. \& \& The following argument is a regular expression that specifies the text \& substrings to wrap in the new elements. An element is created for every \& match in the context element and, if any, in its existing children. \& \& After these arguments, additional attribute/value pairs may be \& optionally provided; each one will become an attribute for every created \& child element (the same name and attributes apply to all). Every \& attribute name provided without namespace prefix is automatically \& concatenated to the same namespace prefix as the new elements. \& \& This method returns the new child elements as a list. \& \& Note that splitContent() is a simplified interface for the mark() \& method provided by XML::Twig, which may be directly used as an element \& method for more advanced uses. .Ve .PP \fIsplitElement(element, offset)\fR .IX Subsection "splitElement(element, offset)" .PP .Vb 5 \& Splits a text element at a given offset. This method is a wrapper \& of the XML::Twig::Elt split_at() method, so, as said by Michel \& Rodriguez in his documentation, it splits "a text element in 2" at \& the given offset so "the original element now holds the first part \& of the string and a new element holds the right part". \& \& In addition, the new element is created with the same attributes (ex: \& the style or the heading level, if any) as the original one. \& \& The new element is inserted immediately after the old one. \& \& The method returns both the original and the new elements in a list \& context. In a scalar context, the new element only is returned. \& \& Caution: splitElement() works properly on elements containing "flat \& text" only. It\*(Aqs a bit complicated to use and probably doesn\*(Aqt \& produce the right effects on elements containing line breaks, tab \& stops, "styled spans" or any kind of structure. If it\*(Aqs used with an \& element containing more that one text segment, it works with the first \& one only. .Ve .PP \fItabStop\fR .IX Subsection "tabStop" .PP .Vb 4 \& Returns a special tabulation mark element, available for insertion \& within an existing text element (knowing that "\et" is not recognized \& as a tab stop if stored "as is"). The returned element is free, so \& it could/should be inserted later within a text element. .Ve .PP \fIuserFieldValue(user_field [, value])\fR .IX Subsection "userFieldValue(user_field [, value])" .PP .Vb 4 \& Reads the stored value of a given user field or changes it if a \& value is provided. The 1st argument can be either the name of the \& field (as it appears for the end\-user) or a previously loaded \& user field element. See also getUserField(). \& \& This method doesn\*(Aqt create any new user field. It can only read or \& update an existing one. \& \& If the given user field is numeric (ex: date, currency) the returned \& and/or provided value is the internally stored value, and not the \& displayed one. \& \& Warning: the changes made in a document using userFieldValue() don\*(Aqt \& necessarily produce visible changes for the end\-user. This method \& can update the internal value of a field, but the displayable \& representations of this field are not automatically refreshed (it \& depends on a later field update). .Ve .PP \fIvariableValue(name/element [, newvalue])\fR .IX Subsection "variableValue(name/element [, newvalue])" .PP .Vb 3 \& Returns the current value of the given user\-defined variable or, if \& a new value is provided as the second argument, updates the variable \& accordingly. \& \& [Contribution by Andrew Layton] .Ve .SS "Element methods" .IX Subsection "Element methods" .Vb 6 \& Every document element is an OpenOffice::OODoc::Element object, \& and OpenOffice::OODoc::Element inherits all the rich features of \& XML::Twig::Elt, including the very powerful copy(), cut(), paste(), \& move() and replace() methods (look at the XML::Twig documentation \& for details). Some additional methods, provided in the ::Element \& package, are described below. \& \& The "element methods" should be regarded as reserved for advanced \& uses, possibly in combination with native XML::Twig::Elt methods \& (not documented here, but the XML::Twig package itself is well \& documented). \& \& Remember these methods belong to the element and not to the \& document...! .Ve .PP \fIappendChild(newnode)\fR .IX Subsection "appendChild(newnode)" .PP .Vb 1 \& Appends a node as the last child of the calling node. \& \& If the argument is an existing node, it\*(Aqs appended as is. \& If the argument is a string, a new node is created, with the \& given string as the XML tag name. .Ve .PP \fIappendTextChild(text)\fR .IX Subsection "appendTextChild(text)" .PP .Vb 2 \& Appends a text node (PCDATA) as the last child of the calling \& element. .Ve .PP \fI\fIflatten()\fI\fR .IX Subsection "flatten()" .PP .Vb 9 \& Converts in place the content of the calling element to a flat string, \& removing any structure. All the children of the calling element are \& removed and their text content is concatenated. The resulting string \& becomes the only content of the element. For example, if the calling \& element is a table, the tabular structure disappears and is replaced \& by the concatenated contents of all the cells. Any possible internal \& tab stop or line break element is removed, as well as any "styled" \& text span (see setSpan() and removeSpan() is the OODoc::Text chapter \& for information about styled text spans). \& \& Be careful, a lot of elements are not displayed by the OpenDocument \& compliant software. For example, a section element becomes invisible \& if it directly contains its text, without structure elements such as \& paragraphs, headings, tables, and so on. In order to make visible the \& "flattened" content of a previously complex element, the XML tag \& should be replaced by the tag of a "displayable" element. In the \& following example, a section is flattened, then tagged as a \& paragraph, so its content remains visible: \& \& my $s = $doc\->getSection("AnySection"); \& $s\->flatten; \& $s\->set_tag(\*(Aqtext:p\*(Aq); \& \& Note: getSection() belongs to OpenOffice::OODoc::Text and set_tag() \& is provided by the underlying XML::Twig::Elt package. \& \& The text flattening is sometimes required in order to allow the \& applications to retrieve strings which are split into more than one \& text container. For example, a string such as "OpenDocument" can\*(Aqt \& be retrieved using selectElements() or any other string search method \& of the API if, say, "Open" and "Office" don\*(Aqt belong to the same text \& span (i.e. if they have different styles; look at setSpan() in \& OpenOffice::OODoc::Text to know more about text spans). In such a \& situation, flatten() removes any text span markup, so the whole text \& content of the element can be processed as a regular character string. \& \& Caution, this method can produce terrific results when misused. .Ve .PP \fIgetLocalPosition([regexp])\fR .IX Subsection "getLocalPosition([regexp])" .PP .Vb 2 \& Returns the position of the current element in the list of all \& the children of the same parent with the same type. \& \& Example: \& \& $cell\->getLocalPosition(); \& \& Assuming $cell is a table cell, this example returns the position \& of the cell in the row without counting the covered cells (if any). \& \& If a regular expression is provided as the optional argument, all \& the siblings matching the expression are counted; but the method \& returns zero if the calling element itself doesn\*(Aqt match the \& expression. \& \& Example: \& \& $cell\->getLocalPosition(qr\*(Aqtable:(covered\-|)table\-cell\*(Aq); \& \& returns the position of the cell among all the cells (covered or not) \& in the row. \& \& Note: This method is a wrapper of the pos() method of XML::Twig::Elt, \& but the returned values are zero\-based in order to be consistent \& with the other element addressing features of OpenOffice::OODoc. .Ve .PP \fIinsertNewNode(xml_tag, position_flag [, offset])\fR .IX Subsection "insertNewNode(xml_tag, position_flag [, offset])" .PP .Vb 5 \& Creates a new XML element, whose tag is passed as the 1st argument, \& before, after or within the calling element. The 2nd argument \& must be set to \*(Aqbefore\*(Aq, \*(Aqafter\*(Aq, \*(Aqwithin\*(Aq, or any other value \& accepted by the paste() method of XML::Twig. If the 2nd argument \& is \*(Aqwithin\*(Aq, a 3rd one must be provided and indicate the offset. .Ve .PP \fIreplicateNode(count, position)\fR .IX Subsection "replicateNode(count, position)" .PP .Vb 8 \& Produces one or more copies of the calling element and inserts \& the copies before or after it. The position argument should be \& \*(Aqbefore\*(Aq or \*(Aqafter\*(Aq; its default is \*(Aqafter\*(Aq. Technically, the \& position argument could be anyone of the position options of \& the XML::Twig::Elt\->paste method, including \*(Aqfirst_child\*(Aq, \& \*(Aqlast_child\*(Aq or \*(Aqwithin\*(Aq; but any other than \*(Aqbefore\*(Aq and \*(Aqafter\*(Aq \& probably don\*(Aqt make sense in an OpenDocument\-compliant data \& structure. \& \& Without any argument, the calling element is replicated once. \& But if the count argument is provided and set to zero or a \& negative value, nothing is done. \& \& Example : \& \& my $row = $doc\->getTableRow("Table1", \-1); \& $row\->replicateNode(5); \& \& This sequence appends 5 more rows to a table; each new row is a \& copy of the last original row, including each individual cell \& and its content. .Ve .PP \fIselectChildElement(filter)\fR .IX Subsection "selectChildElement(filter)" .PP .Vb 2 \& Like selectChildElements() below, but returns only the first node \& matching the filter. \& \& Note: the first_child() method of XML::Twig::Elt should be preferred \& when the filter is the exact tag name of the needed element. .Ve .PP \fIselectChildElements(filter)\fR .IX Subsection "selectChildElements(filter)" .PP .Vb 2 \& Selects the children with XML tag names matching a given filter. \& The filter is processed as a regexp. \& \& Note: the children() method of XML::Twig::Elt should be preferred \& if the filter is the exact tag name of the needed elements. .Ve .PP \fI\fItextLength()\fI\fR .IX Subsection "textLength()" .PP .Vb 2 \& Works with text nodes. In array context, returns the length of the text \& and the text itself; in scalar context, returns the length only. .Ve .SS "Properties" .IX Subsection "Properties" .Vb 2 \& No class variables are exported; the applications, if needed, \& must access them using their full name ($OpenOffice::OODoc::XPath:XXX) \& \& The following names should be prefixed explicitly with \& "$OpenOffice::OODoc::XPath::" \& \& CHARS_TO_ESCAPE \& \& contains the list of reserved characters which, in XML, should be \& replaced by escape sequences. \& \& OO_CHARSET \& \& indicates the character set used for OpenDocument document \& encoding and whose default value is \*(Aqutf8\*(Aq (it should not be changed). \& \& LOCAL_CHARSET \& \& indicates the user\*(Aqs character set, by default \*(Aqiso\-8859\-1\*(Aq; it must \& be changed according to the real user\*(Aqs needs (warning: there is no \& kind of automatic adaptation to the user\*(Aqs locales, so the application \& must explicitly load the right value in this variable); it should be \& done using the odfLocalEncoding() accessor (see the OpenOffice::OODoc \& man page and, for the list of supported character sets, the Encode \& module\*(Aqs documentation). \& \& The content of these three variables should not normally be directly \& modified by the applications. \& \& Instance hash variables are : \& \& \*(Aqcontainer\*(Aq => \& \*(Aqfile\*(Aq => \& \*(Aqpart\*(Aq => \& \*(Aqreadable_XML\*(Aq => <\*(Aqtrue\*(Aq or \*(Aqfalse\*(Aq> \& \*(Aqlocal_encoding\*(Aq => \& \*(Aqmultiple_spaces\*(Aq => <\*(Aqon\*(Aq or undef, see setText()> \& \*(Aqelement\*(Aq => \& \*(Aqxpath\*(Aq => \& \*(Aqtwig_options\*(Aq => \& \*(Aqopendocument\*(Aq => <\*(Aqtrue\*(Aq or \*(Aqfalse\*(Aq> \& \& However, the \*(Aqxml\*(Aq variable is cleared almost immediately after a \& successful constructor call, in order to save memory. As soon as the \& corresponding XPath object has been created, the XML source is no \& longer required. \& \& The \*(Aqxpath\*(Aq variable of an OODoc::XPath object contains a reference \& to the document structure as it\*(Aqs made available through XML::Twig \& (see CPAN documentation). This object encompasses the entire current \& XML tree. Each access to XML using OODoc::XPath objects is done via \& XML::Twig. So, after having run the following command: \& \& my $xp = $doc\->{\*(Aqxpath\*(Aq}; \& \& the experienced programmer will be able to use $xp to access all the \& functionality of the XML::Twig API, bearing in mind that all \& operations using this interface will have a direct effect on the \& content of the $doc object. \& \& \*(Aqtwig_options\*(Aq allows the user to provide a hash reference of \& additional options to XML::Twig. These options can modify the way the \& document is parsed during the execution of odfXPath(). For special \& applications only (see the XML::Twig reference manual). \& \& The \*(Aqopendocument\*(Aq property, if true, means that the document is \& declared as an OASIS Open Document. If this property is false or \& undef, the document format is OpenOffice.org version 1. This property \& should not be changed (as long as OpenOffice::OODoc can\*(Aqt change the \& format of an existing document). .Ve .SH "AUTHOR/COPYRIGHT" .IX Header "AUTHOR/COPYRIGHT" Developer/Maintainer: Jean-Marie Gouarne .PP Contact: jmgdoc@cpan.org .PP Copyright 2004\-2010 by Genicorp, S.A. .PP Initial English version of the reference manual by Graeme A. Hunter (graeme.hunter@zen.co.uk). .PP License: \s-1GNU\s0 Lesser General Public License v2.1