473,322 Members | 1,431 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

how to get the output in xml format

Hi every one I was trying to do login page in titanium android.

In that I did authentication in Asp.net.

Now I want to send that result in XML format.

Can any one help please?

Here is my code:
Expand|Select|Wrap|Line Numbers
  1. protected void Page_Init(object sender, EventArgs e)
  2.     {
  3.         string username = Request.QueryString["username"];
  4.         string password = Request.QueryString["password"];
  5.         int response;
  6.         string constr = "Data Source=ITS-BA-DC02\\MSSQL2008_SAND;Initial Catalog=TestDB_Chaitanya;User ID=sa;Password=01Explore";
  7.         SqlConnection conn = new SqlConnection(constr);
  8.         conn.Open();
  9.         SqlCommand cmd = new SqlCommand("select username, password from users where username = '" + username + "'and password='" + password + "'", conn);
  10.         SqlDataReader dr = cmd.ExecuteReader();
  11.         if (dr != null && dr.HasRows)
  12.         {
  13.  
  14.             string str = "Login Successful!";
  15.             Response.Write(str);
  16.         }
  17.         else
  18.         {
  19.             string str1 = "Invalid username or password!";
  20.             Response.Write(str1);
  21.         }
  22. }
  23. }
Here instead of sending output in string I want to send that message in XML format
Dec 20 '11 #1
3 2063
Hi
You can write the xml code using Response.Write with your expected xml format.
ex:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?>
  2. <result>
  3.      Login Successful!
  4. </result>

Code :
Expand|Select|Wrap|Line Numbers
  1. Response.Write("<?xml version=""1.0""?>")
  2. Response.Write("<result>")
  3. Response.Write(str1);
  4. Response.Write("</result>")
Dec 20 '11 #2
Response.Write("<?xml version=""1.0""?>" here it is showing errors as:

Expand|Select|Wrap|Line Numbers
  1. Error    3    ) expected    C:\inetpub\wwwroot\MobileApp\Default.aspx.cs    26    43    http://localhost/MobileApp/
  2.  
  3. Error    4    ; expected    C:\inetpub\wwwroot\MobileApp\Default.aspx.cs    26    46    http://localhost/MobileApp/
  4.  
  5. Error    5    Invalid expression term ')'    C:\inetpub\wwwroot\MobileApp\Default.aspx.cs    26    50    http://localhost/MobileApp/
  6.  
  7. Error    6    ; expected    C:\inetpub\wwwroot\MobileApp\Default.aspx.cs    26    50    http://localhost/MobileApp/
Dec 20 '11 #3
Frinavale
9,735 Expert Mod 8TB
You are getting the errors because you copied and pasted the code incorrectly and the code you copied was a mix between VB.NET and C# code.
Expand|Select|Wrap|Line Numbers
  1. StringBuilder str;
  2. str = new StringBuilder();
  3.  
  4. str.Append("<?xml version=""1.0""?>");
  5. str.Append("<result>");
  6. str.Append(str1);
  7. str.Append("</result>");
  8. Response.Write(str.ToString());
You should change the content type of the Response to "xml" so that the browser knows that it isn't receiving HTML when it is sent the data.

Like this:

Expand|Select|Wrap|Line Numbers
  1. //makes sure to clear out any html
  2. Response.Clear();
  3. //sets the type to xml so that the browser knows what its getting
  4. Response.ContentType = "text/xml";
  5. //ensuring that the angle brackets aren't encoded as &lt; and &gt;
  6. Response.ContentEncoding = System.Text.Encoding.UTF8; 
  7.  
-Frinny
Dec 20 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

16
by: David | last post by:
I have following code. float b; b= 1.234; cout<<hex<<b<<endl; How come it cannot ouput the hex representation of b?
3
by: Clark Spencer | last post by:
I have built a small integration app using VS .NET 2003 that extracts orderinformation from a 'webshop'. Extracting the orderinformation works fine. Appending the order elements in the...
0
by: Karthik | last post by:
Hi I have two problems in using FOP with SVG as output format: 1. External Gifs are not coming out in the output SVG file when I use via TOP Transform (with RENDER_SVG): ...
4
by: hph | last post by:
Okay, another trivial matter that I can't solve. I have a variable - $lastdate - that is the latest date any record in a MySQL database was updated. Its MySQL format is TIMESTAMP. If I say I...
20
by: Ilias Lazaridis | last post by:
IDLE has an output format like this: <type 'object'> <type 'type'> <type 'type'> How can I customize it to become like that: <type 'object'> <type 'type'>
1
by: nriley | last post by:
Hi, I've got a number of doctests which rely on a certain output format, and since I wrote the tests I've changed the output format. Now, almost all the tests fail. What I'd like is if I...
2
by: ayan4u | last post by:
ok i have two problems... firstly in strict C enviornment is it possible to have a true dynamic charecter array with no predefined length...i mean to say... suppose.. char *array =NULL;...
1
rhitam30111985
by: rhitam30111985 | last post by:
Hi all , i am using logparser 2.2 to reduce the number of repetative errors from master log file . the syntax of my query is somewhat like this : logparser -i:TSV -o:TSV -q:on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.