Home » Infrastructure » Windows » Download XML Data using ODP.Net (Oracle Database 11.2.0.2.0 - 64bit, OPD.Net 2.112.2.0)
Download XML Data using ODP.Net [message #541455] Tue, 31 January 2012 08:10
annagel
Messages: 220
Registered: April 2006
Senior Member
I am looking for a method to stream XML formatted data from the database via an ASP.Net website. Our basic method for this has been:

  1. Create PL/SQL function which returns XMLType
  2. Convert the XMLType to a string via the "Value" property
  3. Set headers and write the string to the Response object

This typically works well enough as most of our downloads are fairly small so caching all the XML data on the server is not a big deal. With larger files though we need to load more and more data onto the server and so we started to investigate the possibility of streaming the data directly down to the user before we have it loaded fully using the OracleXMLStream object like so (omitting the connection open/close and specifics of the database query):

OracleXmlType xml = getXML();
OracleXmlStream xmlStream = new OracleXmlStream(xml);
Response.Clear();
Response.AddHeader("Content-Disposition","data.xml");
Response.ContentType = "text/xml";
byte[] buffer = new byte[0x1000];
int read;
while ((read = xmlStream.Read(buffer, 0, buffer.Length)) > 0)
     Response.OutputStream.Write(buffer, 0, read);
Response.Flush();
Response.End();


This works, but the character encoding is preventing IE from reading the XML output. I can fix this by reading the character data out instead of the binary data and re-encoding myself using the character encoding classes, but is there another method I could use for this? Or am I going about this whole thing wrong?
Previous Topic: I do not know to create ASM disk on Windows
Next Topic: dim 00019 : Create Service Error
Goto Forum:
  


Current Time: Thu Mar 28 05:38:46 CDT 2024