Skip Menu |

This queue is for tickets about the OpenOffice-OODoc CPAN distribution.

Report information
The Basics
Id: 62277
Status: resolved
Priority: 0/
Queue: OpenOffice-OODoc

People
Owner: Nobody in particular
Requestors: r.limanowski [...] nttcable.de
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: (no value)



Subject: getElement does not work
Date: Tue, 19 Oct 2010 17:18:45 +0200
To: bug-OpenOffice-OODoc [...] rt.cpan.org
From: Richard Limanowski <r.limanowski [...] nttcable.de>
Hello, I discovered, that the functionality of OpenOffice::OODoc::XPath changed between versions 2.223 and 2.237 in the sense, that a call to getElemet(), which returned a value in the earlier version returns undef in the newer version. Please find attached a small demo consisting of: 1. test.odt - small document containing macro library 2. test.pl - script to illustrate the problem Call it like: perl -d test.pl test.od I do not have much experience in using your library and ran into problems while trying to move from debian etch to squeeze. The code aims at replacing/extending the library by a macro (attached) allowing us to save back an OpenOffice-Document using vanila apache with webdav module. Reagrds, -- Richard Limanowski NTTCable GmbH IT
Download test.odt
application/octet-stream 8.7k

Message body not shown because it is not plain text.

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> <script:module xmlns:script="http://openoffice.org/2000/script" script:name="nttmacro" script:language="StarBasic">REM ***** BASIC ***** Sub NttOpenDocEvent SaveWebDAV DisableDesignMode End Sub Sub SaveWebDAV Dim oDoc Dim Dummy() oDoc = ThisComponent &apos; If ! oDoc.hasLocation() then &apos; MsgBox(&quot;This is a new file so Save it in the normal manner. Quitting.&quot;) &apos; End &apos;EndIf odoc.storeAsURL(&quot;<FILE_NAME>&quot;, Dummy()) &apos;odoc.storeAsURL(&quot;file:///tmp/test123456.odt&quot;, Dummy()) End Sub sub DisableDesignMode rem ---------------------------------------------------------------------- rem Disables the design mode for the current document, allowing the user rem to fill out formulares without manual disabling this mode. rem Created with macro recorder... rem ---------------------------------------------------------------------- rem rem ---------------------------------------------------------------------- rem define variables dim document as object dim dispatcher as object rem ---------------------------------------------------------------------- rem get access to the document document = ThisComponent.CurrentController.Frame dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;) rem ---------------------------------------------------------------------- dim args1(0) as new com.sun.star.beans.PropertyValue args1(0).Name = &quot;SwitchControlDesignMode&quot; args1(0).Value = false dispatcher.executeDispatch(document, &quot;.uno:SwitchControlDesignMode&quot;, &quot;&quot;, 0, args1()) end sub </script:module>
#!/usr/bin/perl -w use strict; use OpenOffice::OODoc; use OpenOffice::OODoc::XPath; use Data::Dumper; my $file = shift; my $ofile = ooFile($file); my $basic = OpenOffice::OODoc::XPath->new( member => 'Basic/script-lc.xml', element => 'library:libraries', file => $ofile ); my $elem = $basic->getElement('//library:libraries'); # this yields something when using # our $VERSION = 2.223; # use XML::Twig 3.22; # # but undef when using # our $VERSION = '2.237'; # use XML::Twig 3.32; # have to supply undocumented context parameter $elem = $basic->getElement('//library:libraries', 0, $basic->{'xpath'}); print "why?\n"; exit(0);
Le Mar 19 Oct 2010 11:19:01, r.limanowski@nttcable.de a écrit : Show quoted text
> Hello, > > I discovered, that the functionality of OpenOffice::OODoc::XPath > changed between versions 2.223 and 2.237 in the sense, that > a call to getElemet(), which returned a value in the earlier version > returns undef in the newer version.
Hello Richard, The wrong behavior comes from a change in the default XPath search context, that was the whole XML part in 2.223 and that is now the root node. This change should be transparent for every regular element but, unfortunately, your application uses getElement() in order to get the root node itself (i.e. the library:libraries element). Yes, this limit use case should have been documented and it's not (mea culpa). However, generally speaking, getRoot() is more smart and efficient than getElement() if you want to get the root element of any document member; using getRoot() you don't have to specify the name of the element name. See http://search.cpan.org/dist/OpenOffice-OODoc/OODoc/XPath.pod#getRoot() However, if for any reason you prefer getElement(), you can switch it to the old behavior. To do so in your example, you have to put a $basic->currentContext($basic->{xpath}) instruction somewhere before getElement(). But it's not my recommendation. Thanks for your report Please let me know through this bug tracker if the workaround above works for you.
Subject: Re: [rt.cpan.org #62277] getElement does not work
Date: Wed, 20 Oct 2010 13:08:50 +0200
To: bug-OpenOffice-OODoc [...] rt.cpan.org
From: Richard Limanowski <r.limanowski [...] nttcable.de>
Hello Jean-Marie, your suggested method works for me. Thank you very much for your explanation and engagement! Yours, Richard Limanowski Am 20.10.2010 10:15, schrieb Jean-Marie Gouarné via RT: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=62277> > > Le Mar 19 Oct 2010 11:19:01, r.limanowski@nttcable.de a écrit :
>> Hello, >> >> I discovered, that the functionality of OpenOffice::OODoc::XPath >> changed between versions 2.223 and 2.237 in the sense, that >> a call to getElemet(), which returned a value in the earlier version >> returns undef in the newer version.
> > Hello Richard, > > The wrong behavior comes from a change in the default XPath search > context, that was the whole XML part in 2.223 and that is now the root > node. This change should be transparent for every regular element but, > unfortunately, your application uses getElement() in order to get the > root node itself (i.e. the library:libraries element). Yes, this limit > use case should have been documented and it's not (mea culpa). > > However, generally speaking, getRoot() is more smart and efficient than > getElement() if you want to get the root element of any document member; > using getRoot() you don't have to specify the name of the element name. See > http://search.cpan.org/dist/OpenOffice-OODoc/OODoc/XPath.pod#getRoot() > > However, if for any reason you prefer getElement(), you can switch it to > the old behavior. To do so in your example, you have to put a > $basic->currentContext($basic->{xpath}) instruction somewhere before > getElement(). But it's not my recommendation. > > Thanks for your report > Please let me know through this bug tracker if the workaround above > works for you. > > > >