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 7077999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:29:33+00:00 2026-05-28T06:29:33+00:00

I have this code to generate Xml from an IQueryable variable query: XDocument data

  • 0

I have this code to generate Xml from an IQueryable variable query:

XDocument data = XDocument.Load(HttpContext.Current.Server
                                           .MapPath("~/XMLFile.xml"));
XElement newTest = new XElement("TestForPackage",
                      from Tests in query.AsEnumerable()
                      select new  XElement("Tests",
                             new XElement("Dep_Code", Tests.Dep_Code),
                             new XElement("Dep_Name", Tests.Dep_Name),
                             new XElement("Test_Code", Tests.Test_Code),
                             new XElement("Test_Name", Tests.Test_Name),
                             new XElement("Sub_Test_Code", Tests.Sub_Test_Code),
                             new XElement("Sub_Test_Code", Tests.Sub_Test_Name)
                      ));

data.Element("TestsForPackage").Add(newTest);
data.Save(HttpContext.Current.Server.MapPath("~/XMLFile.xml"));

It generates xml in the format below:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<TestsForPackage>
  <Test>
    <Dep_Code>BIOCH</Dep_Code>
    <Dep_Name>BIOCHEMISTRY</Dep_Name>
    <Test_Code>BGPP</Test_Code>
    <Test_Name>BLOOD GLUCOSE P.P.</Test_Name>
    <Sub_Test_Code />
    <Sub_Test_Name />
  </Test>

  <Test>
     <Dep_Code>BIOCH</Dep_Code>
     <Dep_Name>BIOCHEMISTRY</Dep_Name>
     <Test_Code>BGPP</Test_Code>
     <Test_Name>BLOOD GLUCOSE P.P.</Test_Name>
     <Sub_Test_Code />
     <Sub_Test_Name />
  </Test>

  <Test>
     <Dep_Code>BIOCH</Dep_Code>
     <Dep_Name>BIOCHEMISTRY</Dep_Name>
     <Test_Code>BGPP</Test_Code>
     <Test_Name>BLOOD GLUCOSE P.P.</Test_Name>
     <Sub_Test_Code />
     <Sub_Test_Name />
  </Test>      
</TestsForPackage>

However, I need to generate xml file in this format:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<TestsForPackage>
  <Test>
    <Dep_Code>BIOCH</Dep_Code>
    <Dep_Name>BIOCHEMISTRY</Dep_Name>
    <Test_Code>BGPP</Test_Code>
    <Test_Name>BLOOD GLUCOSE P.P.</Test_Name>
    <Sub_Test_Code />
    <Sub_Test_Name />
  </Test>

  <Test>
     <Dep_Code>BIOCH</Dep_Code>
     <Dep_Name>BIOCHEMISTRY</Dep_Name>
     <Test_Code>BGPP</Test_Code>
     <Test_Name>BLOOD GLUCOSE P.P.</Test_Name>
     <Sub_Test_Code />
     <Sub_Test_Name />
  </Test>

  <Test>
    <Dep_Code>BIOCH</Dep_Code>
     <Dep_Name>BIOCHEMISTRY</Dep_Name>
     <Test_Code>BGPP</Test_Code>
     <Test_Name>BLOOD GLUCOSE P.P.</Test_Name>
     <Sub_Test_Code />
     <Sub_Test_Name />
  </Test>

</TestsForPackage>

I know I am making some minor mistake but I don’t know what it is.

  • 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-05-28T06:29:34+00:00Added an answer on May 28, 2026 at 6:29 am

    XML is all about semantics, it is a mechanism for transmission and exchange of data. An XML parser doesn’t care about the whitespace in your file. For this reason, XML writers do not allow you to control the whitespace output (other than giving your the option to pretty-print).

    If you want to be specific about where the line-breaks are in your XML output, you are going to have to manipulate the XML output yourself using string manipulation.

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

Sidebar

Related Questions

I'm using this code in order to generate XML from my grid's cells values:
I have this php code, with which I am trying to generate a popup
I'm using StringTemplate to generate some xml files from datasets. Sometimes I have more
What tools have you used to create class source code from xml files? Is
I have an application that extracts data from some xml that is stored in
I have a need to generate XML documents from C++. For reasons of performance
I have this code try { //AN EXCEPTION IS GENERATED HERE!!! } catch {
I have some LINQ code that generates a list of strings, like this: var
I have some C# code that generates google maps. This codes looks at all
I have this code in jQuery, that I want to reimplement with the prototype

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.