| View previous topic :: View next topic |
| Author |
Message |
Guest
|
Posted: Fri Jun 25, 2004 10:54 am Post subject: How can I create, fill and save an utf-8 encoded text file? |
|
|
Hello,
I write an export of a complete Writer doc into a special xml format. Therefore, the xml-file should be utf-8 encoded. At the present we use a simple file output via freefile, that do not save as needed.
How can I open a file, writing strings in it and then save it as an utf-8 encoded text file? I found the xTextOutputstream, that seams to be usefull, but I could not found any code example.
Thank you for your help
Harry |
|
| Back to top |
|
 |
zap General User

Joined: 28 May 2004 Posts: 40
|
Posted: Sat Jun 26, 2004 8:03 am Post subject: |
|
|
do you know which encoding your own filter uses? When we need utf8 from a program that doesn't support it, we send the file through iconv afterwards.
see
http://www.scit.wlv.ac.uk/cgi-bin/mansec?1+iconv
Our OO saves in utf8 format, do you have more details on your filter?
there is probably a windows version, too
zap |
|
| Back to top |
|
 |
harrybo Power User


Joined: 27 Apr 2004 Posts: 62 Location: Germany
|
Posted: Sat Jun 26, 2004 8:40 am Post subject: |
|
|
Hello zap,
thank you for your replay. I'm not shure, wich encoding is used. I'm working on a windows XP system, and the file that receives the data is opened by the following procedure:
| Code: | Sub InitExportFile
if FileExists(gsExportXML) then
Kill gsExportXML
end if
giExportXML = Freefile
Open gsExportXML For Output As #giExportXML
End Sub
'writing into the export file with:
'Print #giExportXML, "Hello world"
|
I do not know, which filter that method uses. Probalby it would be a better idea to open a XTextOutputStream in OO-Basic, that supports Filter settings. As I red in the Developer Guide, the utf-8 filter is the default setting. Unfortunately, I do not know how to write a working code for opening that stream, what means, creating a new local file, and then to send data to this file (I'm trying the whole day now - it's a little bit frustrating).
Regards, Harry
P.S.: Your "iconv" solution might run, but how to implement this in OO-Basic? |
|
| Back to top |
|
 |
Cybb20 Super User


Joined: 02 Mar 2004 Posts: 1572 Location: Frankfurt, Germany
|
Posted: Sat Jun 26, 2004 11:18 am Post subject: |
|
|
The xTextoutputStream interface has the following description:
| Quote: | Interface to write strings to a stream using a special character encoding.
This interfaces allows to write strings to a stream. The character encoding to be used can be set by setEncoding() . Default encoding is "utf8". |
This means we don't have to set any Encoding cause utf8 is already the default.
The following code should do what you want:
| Code: |
fileAccessService = createUnoService("com.sun.star.ucb.SimpleFileAccess")
textOutputStream = createUnoService("com.sun.star.io.TextOutputStream")
'now open the file..
outputStream = fileAccessService.openFileWrite(<yourFileName>)
outputStream.truncate()
textOutputStream.setOutputStream(outputStream)
'now write something into the file
textOutputStream.writeString("This is utf-8 format.")
'and don't forget to close it..
textOutputStream.closeOutput()
|
Hope that helps.
Christian _________________ - Knowledge is Power - |
|
| Back to top |
|
 |
harrybo Power User


Joined: 27 Apr 2004 Posts: 62 Location: Germany
|
Posted: Sat Jun 26, 2004 3:59 pm Post subject: |
|
|
Hello cybb20,
this is exactly what I was looking for. It works fine. Thank 's a lot, that really helped me.
Harry |
|
| Back to top |
|
 |
|
|
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
|