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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:49:32+00:00 2026-06-07T12:49:32+00:00

I serialize simply Person which has Items as collection using .NET XmlSerializer; class Item

  • 0

I serialize simply Person which has Items as collection using .NET XmlSerializer;

class Item
{
   Name
   Price
}

class Person
{
   Name
   List Items<Item>
}

Everthing fine…I use XmlWriterSettings to indent my xml file. The output is:

   <?xml version="1.0" encoding="utf-8"?>
<Person xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <name>TestName</name>
  <Items>
    <Item>
      <name>one</name>
      <price>0</price>
    </Item>
    <Item>
      <name>two</name>
      <price>1</price>
    </Item>
  </Items>
</Viewport>

But what I want is :

<?xml version="1.0" encoding="utf-8"?>
<Person xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <name>TestName</name>
  <Items>
     <Item name="one" price="0" />
     <Item name="two" price="1" />
  </Items>
</Viewport>

Shortly instead of

<Item>
      <name>one</name>
      <price>0</price>
 </Item>

I want to write xml as

<Item name="one" price="0" />

How can i do it in .NET(C#) ?

  • 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-07T12:49:33+00:00Added an answer on June 7, 2026 at 12:49 pm

    Decorate your Name & Price properties with XmlAttribute

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

Sidebar

Related Questions

I have a service that attempting to serialize a list into JSON (using JSON.NET)
I have a relatively simple class. I serialize it using JDK 1.7 on my
I am using boost::variant and boost::serialize in my application. The serialization module has built
So I am trying to simply decorate a class to serialize it as XML.
I'm trying to serialize a list of python objects with JSON (using simplejson) and
I am using an XmlSerializer to serialize an object to xml. After the object
Here is a structure I serialize in my project: [Serializable] class A : List<B>
I want to serialize a nullable bool simply by converting it to a string
I'd like to serialize some simple data model into xml, I've been using the
I have a simple Java class that I need to serialize to be stored

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.