OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Import data from XML file into existing oofile

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
Piet
Guest





PostPosted: Sat Jan 17, 2004 1:42 am    Post subject: Import data from XML file into existing oofile Reply with quote

Hi there!
After a lot of experimentation, Iīve learned to import data from xml files into Word and Excel via VBA macros using the MSXML 3.0 parser functions. Now I am looking for a similar possibility in ooorg to. Donīt get me wrong: I donīt not want to transform a native xml file into an ooorg file (or export a complete file to a flat xml file), but I would like to have a function available as a macro or (even better) a menu itme saying "import data from expenses.xml" and then have the data inserted e.g. as a table in oowriter or in specific cells in oocalc. So two main issues will have to be addressed:
1. Create a table in oowriter and have a way to address the cells of this table or adress the cells of an oocalc spreadsheet (together with more elaborate functions such as combining two or more cells to one, defining cell border styles etc.). I assume that this can be achieved in a straightforward way because the functions are already implemented in ooorg and will "only" have to be carried out in an automated way.
2. Open an xml file and access the desired data with xpath/DOM expressions. This sounds more challenging.
Any hints how to address this question?
btw, I would not call myself a programmer. I know xml and xpath and I figured out somehow how to make things work in msoffice, but I have basically no idea about the underlying principles such as the windows COM.
Many thanks in advance.
Piet
Back to top
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Sat Jan 17, 2004 10:23 am    Post subject: Reply with quote

Piet wrote:
Iīve learned to import data from xml files into Word and Excel via VBA macros using the MSXML 3.0 parser functions.


I am not familiar with it, but I assume this parses the document into a DOM structure in memory, and that you can then easily navigate through the DOM.

In the latest OOo API docs I only see a SAX type parser, but no DOM parser. It would be possible to write such a parser as an add in module to OOo, but this is a major project. (It sure sounds like a fun one though!)

I have written a post here
http://www.oooforum.org/forum/viewtopic.php?t=4907
showing how to use the SAX parser in OOo.

If you want to write a macro in OOo Basic, it would be possible to use the technique I describe. But it would be a lot more work than what you had to do using MSXML.

Another possibility, if you are on Windows, is NOT to write an OOo Macro. Instead, use a language like VB to manipulate OOo. In VB you could still use the MSXML parser, and then manipulate an OOo document.

Quote:
2. Open an xml file and access the desired data with xpath/DOM expressions


I don't know of anything in OOo to do this. It would be nice. A Java module could be written to provide MSXML like functionality as true OOo services, and then installed into OOo.

Quote:
1. Create a table in oowriter and have a way to address the cells of this table or adress the cells of an oocalc spreadsheet


I don't know much about creating tables in Writer, perhaps one of our resident Writer experts can reply, but here is an example that might help with Calc.
http://www.oooforum.org/forum/viewtopic.php?p=18865
This example shows how to access and manipulate the cells of a spreadsheet.
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
Piet
Guest





PostPosted: Sun Jan 18, 2004 4:27 am    Post subject: Re: xml processing in ooo Reply with quote

Hi Danny!
Thanks a lot for the quick response! In fact, I had assumed that xml processing from within ooo would not only require to use an existing functionality, but indeed to generate a new one. I tolally agree that it would be a very cool function to directly read/write informations from/to XML files from ooBasic using DOM/xPath functions. The MS Office/MSXML things that I have done in the past do their work, but they are not cross platform, of course.
Including that functionality in the oo core is faaaaar beyond my possibilities. I will try to develop some python scripts to do the xml work. Including python scripts as menu points in ooorg is possible and is described in the ooorg/python binding documentation.
IN any case I see lots of fun in the future.
Best regards
Piet
Back to top
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group