Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7733373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:58:18+00:00 2026-06-01T06:58:18+00:00

The following code needs to produce an XML file. string path = @c:\load\myFile.xml; SqlConnection

  • 0

The following code needs to produce an XML file.

string path = @"c:\load\myFile.xml";
        SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["EmpFloors"].ConnectionString);
        SqlCommand cmd;
        cmd = new SqlCommand("select coords.xyid as '@id', xmin, xmax, ymin, ymax,(select brief, long, img from floordesc where coords.xyid = floordesc.xyid for xml path(''),Type) as 'desc' from coords where xyid <> '' for xml path('coord'), Elements XSINIL,root('coords')", connection);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet("coords");
        da.Fill(ds, "coord");
        Response.Write(ds.GetXml());
        File.WriteAllText(path, ds.GetXml());

The XML should look exactly like:

<?xml version="1.0" encoding="iso-8859-1"?>
<coords>
<coord id="6090">
    <title>Office 6090</title>
    <xmin>10</xmin>
    <xmax>60</xmax>
    <ymin>40</ymin>
    <ymax>90</ymax>
    <desc>
        <brief>one</brief>
        <long>one more</long>
        <img>dude.jpg</img>
    </desc>
</coord>
<coord id="11090">....

The Response.Write code writes it out to the page correctly. However, when I try to write to a file, it gets changed to what seems like htmlencoding.

 &lt;coords xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;&lt

I don’t see a way to just write the same text that’s rendered during response.write. Any clues would be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T06:58:20+00:00Added an answer on June 1, 2026 at 6:58 am

    Change your approach. Sorry, I didn’t pick up on the fact that you were using the FOR XML clause.

    In this case, you must use the ExecuteXmlReader, and save the resulting output. Here’s an example:

    var xmlReader = cmd.ExecuteXmlReader();
    var xmlDoc = new XmlDocument();
    xmlDoc.Load(xmlReader);
    xmlReader.Close();
    xmlDoc.Save(path);
    

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the following code to produce an array: // Create new customer
I have the following script to look up an XML file and produce an
I dont understand what would be the problem with the following code. It needs
i have the following code ..i need to loop through end of the file
The following code works, but I'm curious as to why I need the Path
I have the following XML: <products> <product> <name>Flat Panel Monitor</name> <code>LS123</code> <attributes> <attribute> <group>Color</group>
Problem Given the following XML configuration file: <main> <name>JET</name> <maxInstances>5</maxInstances> <parameters> <a>1</a> <b> <b1>test1</b1>
I wrote following code: void *produce(void* arg) { buffer* buff = (buffer *) arg;
I have the following code that I need to add an additonal object to
I need syntax help with the following code logic: I have a code block

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.