aspose file tools*
The moose likes JDBC and the fly likes MSSQL: TO XML clause for ASCII format Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "MSSQL: TO XML clause for ASCII format" Watch "MSSQL: TO XML clause for ASCII format" New topic
Author

MSSQL: TO XML clause for ASCII format

Jonas Sell
Greenhorn

Joined: Jan 09, 2012
Posts: 3
Hi All,

I could need some help with creating an XML file from a Microsoft Server table.

While I understand that this should be a piece of cake using the TO XML clause in the query, I'd like the resulting .xml to be formatted in ASCII (the table contains Unicode nvarchar columns).
Is there any mode for the TO XML clause that lets you define the charset?

(why do I want to do this? I'm supposed to check if this it takes significantly longer than creating unicode .xml)

Alternatively, is there any way to to so using Hibernate? because that's how I filled the table in the first place

I know this topic isn't really JDBC-related, but to me it seemed most fitting to post it here.

TY in advance! Jonas
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19692
    
  20

Welcome to the Ranch!

What are you going to do if the table contains Unicode characters that cannot be displayed in ASCII? ASCII is very limited in the characters it can handle.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Jonas Sell
Greenhorn

Joined: Jan 09, 2012
Posts: 3
Thank you

You're right, there's no real sense in reformatting to ASCII if you've got it in Unicode.
In my scenario, the data is designated for a system that can't handle Unicode. But I still want my db to contain unicode - unless the performance would suffer signficantly because of the transformation.

If I get occasional question marks or squares, that's cool.
Jonas Sell
Greenhorn

Joined: Jan 09, 2012
Posts: 3
I'm still looking for a solution that works with TO XML but if you guys think there's none, I'll have to find a workaround - so what do you think?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19692
    
  20

I've never used TO XML, so that's why I haven't responded. I noticed one possible issue, addressed it, and that was that
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18563
    
    8

The usual way to produce XML for those unfortunate users who can only handle ASCII is to do an identity transformation on the XML document and use US-ASCII as the charset of the output. This will cause the transformed XML to contain character escapes for the non-ASCII characters. However this assumes that the system which is going to process that transformed XML will handle the character escapes in some reasonable way. But the only reasonable way would be for the XML parser on that Unicode-ignorant system to convert them back into the characters they represent, which the Unicode-ignorant system would then not be able to handle.

Bottom line (in my opinion): systems which can only handle ASCII shouldn't be given XML. So I guess I'm rejecting your requirement for ASCII-only XML. But anyway my solutions would require an extra transformation step, which it sounds like you're not keen on doing anyway.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MSSQL: TO XML clause for ASCII format