Skip to content

generate XML

7 messages · Robert, S Devriese

#
Finally, I managed to automatically generate rather simple XML code. In R this is a matrix. The problem concerns how to write that matrix to file. I use write.table and the extension of file .xml Everything works perfect beside coding some language letters (Polish). But the problem disappears when I change the extension to .txt Therefore I write a file with .txt extension and after that I manually change the extension to .xml  - it does not solve the problem. Is it possible to write my matrix or txt file to valid xml file? I need to do it automatically.

Best,
Robert
#
On 01/07/2010 10:13 AM, Robert wrote:
Have you checked the XML package?

If you print the matrix within R, this it look like you want (including
correct langauge encoding? Because in that case, you probably could use
sink (see ?sink).

Stephan
#
Dnia 7 stycznia 2010 10:41 S Devriese <sdmaillist at gmail.com> napisa?(a):
Yes. In R I get correct view. How to use sink? I have the object: my.matrix
and I want to create a file item1.xml How to do it?
#
On 01/07/2010 10:57 AM, robert-mcfadden at o2.pl wrote:
you might try

# open file connection
sink("item1.xml")
# print object
my.matrix
# close file connection
sink()
#
Dnia 7 stycznia 2010 11:30 S Devriese <sdmaillist at gmail.com> napisa?(a):
Unfortunately, It does not code letter appropriate. To #print object it's better to use write.table. But thank you for help.
#
On 01/07/2010 11:36 AM, robert-mcfadden at o2.pl wrote:
Mhh, you could have a look at write.matrix in the MASS package, but I'm
afraid that you might have to specify the encoding explicitly (see
?connections, the section on encoding)
3 days later
#
Dnia 8 stycznia 2010 9:20 S Devriese <sdmaillist at gmail.com> napisa?(a):
Thank you. The matrix that I write are coding in ANSI. I checked it using Notepadd++. A need to convert to UTF-8. Notepad++ do it perfectly. But R unfortunately can't write strings (xml code) as UTF-8. I'm trying to figure out usnig ?Encoding.