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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:56:28+00:00 2026-05-12T13:56:28+00:00

I am using LINQ-To-SQL for database. I am returning the xml content from my

  • 0

I am using LINQ-To-SQL for database.

I am returning the xml content from my web service as follow:
The code:

DataClassesDataContext dc = new DataClassesDataContext();
[WebMethod]
    public List<Books> getBooks()
    {
        return dc.Books.ToList();    
    }

Output:

<ArrayOfBook>
−
<Book>
<bookID>1</bookID>
<title>Programming with Java</title>
<author>Balagurusami</author>
<summary>Summary1</summary>
</Book>
−
<Book>
<bookID>2</bookID>
<title>Programming with C</title>
<author>M.M.Patel</author>
<summary>Summary2</summary>
</Book>
−
<Book>
<bookID>3</bookID>
<title>ASP in 21 Days</title>
<author>K.J. Malai</author>
<summary>Summary3</summary>
</Book>
−
<Book>
<bookID>4</bookID>
<title>Book Title</title>
<author>autho1</author>
<summary>summary4</summary>
</Book>
</ArrayOfBook>

Question:

How can I put custom attributes & nodes in my output?

  • 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-12T13:56:29+00:00Added an answer on May 12, 2026 at 1:56 pm

    Is the XML for human consumption? This is one of those areas where developers get stuck in a rut–they have this perception of what the XML “should” look like, and spend countless hours messing around with attributes and IXmlSerializable in order to get it to look the way they want. After all that wasted time they then sadly realize their application runs no differently than it did when they let the damn framework serialize their classes the way XmlSerializer wanted to.

    Advice: Don’t do it. Walk away. Work on something you actually need to work on.

    Wait, you’re still reading this? Oh well, guess you have to learn somehow.

    Two options: Implement IXmlSerializable or use attributes on your properties. I would strongly suggest you go with option two. With the interface, you must construct and parse the xml yourself, which is harder than it sounds. This is even with the advent of the linq to xml classes (XElement etal). I’ve done that before and it ate up a week of my time dealing with this or that little niggling issue.

    Attributes such as XmlAttribute or XmlElement are the quickest route to instruct the xml serializer how to generate your class’ XML. There are some situations (like collection properties) where you will find it hard to massage the xml using attributes the way you want it (smirk).

    So attributes are the definite better option. Unfortunately for you, you’re serializing linq to sql entities–generated code. You can edit the generated code to add the attributes, but now you’re screwed whenever you have to regenerate. Are you starting to get the feeling you shouldn’t worry so much about what your xml looks like?

    So, in your case, you have no option but to add partial classes for each of your entities and implement IXmlSerializable You can construct your xml many different ways (using 2.0 classes, linq to xml classes, or by using freaking StringBuilder). I’d suggest concentrating on
    the linq to xml classes. If you really want to abuse yourself this way.

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

Sidebar

Ask A Question

Stats

  • Questions 175k
  • Answers 175k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer you have a z-index set on class "div.menu-hover-about" div.menu-hover-about {… May 12, 2026 at 3:02 pm
  • Editorial Team
    Editorial Team added an answer A UserControl is a Component. You don't have to do… May 12, 2026 at 3:02 pm
  • Editorial Team
    Editorial Team added an answer So you're not actually using any XML as such? You're… May 12, 2026 at 3:02 pm

Related Questions

I am using LINQ-to-SQL for an application that queries a legacy database. I need
I am using LINQ to SQL for the first time on a small project.
I have a process in a website (Asp.net 3.5 using Linq-to-Sql for data access)
I am doing a small reporting project that needs to read a lot of

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.