[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details

output xml  with columns as attributes to web browser from Oracle using asp.net with C#

Asked by maqskywalker in Programming for ASP.NET, Oracle SCM

Tags: asp.net with C# and XML

This question is specific to Oracle database. I already know how to achieve this using SQL Server but with sql server I use the Select FOR XML AUTO command but for some reason that won't work with oracle. Then I tried another method shown below with oracle. I am close to getting what I need.

This example is using the HR database that comes with Oracle 10g express edition.
This example uses the EMPLOYEES table in the HR database.

I'm using ASP.net with C# to get data from 3 columns in my oracle table. I want the data from those 3 columns to be output to the browser as xml. I can get the xml to the browser with the following script but it's not the correct format I need.

I called the following script   Employees.aspx

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Configuration" %>
<%@ Import Namespace="System.Data.OracleClient" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
string connStr = "Data Source=127.0.0.1;User ID=HR;Password=HR;Unicode=True";
using (OracleConnection conn = new OracleConnection(connStr))
{
OracleCommand command = new OracleCommand("select FIRST_NAME, LAST_NAME, EMAIL from
EMPLOYEES", conn);
conn.Open();
DataSet ds = new DataSet();
ds.DataSetName = "EMPLOYEES";
ds.Load(command.ExecuteReader(), LoadOption.OverwriteChanges, "EMPLOYEE");
Response.ContentType = "text/xml";
ds.WriteXml(Response.OutputStream);
}
}
</script>

The above scripts outputs xml to the browser that looks like this:

<EMPLOYEES>
  <EMPLOYEE>
    <FIRST_NAME>Steven</FIRST_NAME>
    <LAST_NAME>King</LAST_NAME>
    <EMAIL>SKING</EMAIL>
  </EMPLOYEE>
  <EMPLOYEE>
    <FIRST_NAME>Neena</FIRST_NAME>
    <LAST_NAME>Kochhar</LAST_NAME>
    <EMAIL>NKOCHHAR</EMAIL>
  </EMPLOYEE>
  <EMPLOYEE>
    <FIRST_NAME>Lex</FIRST_NAME>
    <LAST_NAME>De Haan</LAST_NAME>
    <EMAIL>LDEHAAN</EMAIL>
  </EMPLOYEE>
  <EMPLOYEE>
    <FIRST_NAME>Alexander</FIRST_NAME>
    <LAST_NAME>Hunold</LAST_NAME>
    <EMAIL>AHUNOLD</EMAIL>
  </EMPLOYEE>
</EMPLOYEES>


But I need it to output the xml with the table columns as attributes, so I need it to look like this.
Can anyone help with getting by xml from oracle to output to the browser to look like this:


<?xml version="1.0" encoding="utf-8" ?>
<EMPLOYEES>
<EMPLOYEE FIRST_NAME="Steven" LAST_NAME="King" EMAIL="SKING" />
<EMPLOYEE FIRST_NAME="Neena" LAST_NAME="Kochhar" EMAIL="NKOCHHAR" />
<EMPLOYEE FIRST_NAME="Lex" LAST_NAME="De Haan" EMAIL="LDEHAAN" />
<EMPLOYEE FIRST_NAME="Alexander" LAST_NAME="Hunold" EMAIL="AHUNOLD" />
</EMPLOYEES>
[+][-]10/27/09 03:59 AM, ID: 25670910Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/27/09 05:22 AM, ID: 25671545Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/27/09 06:04 AM, ID: 25671904Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/27/09 09:49 AM, ID: 25674621Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/28/09 05:08 AM, ID: 25682283Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/20/09 06:31 PM, ID: 25876066Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92 - Hierarchy / EE_QW_3_20080625