[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Serialization duplicate tags c#

Posted on 2010-09-21
3
Medium Priority
?
523 Views
Last Modified: 2013-12-16
Concept: :
************
I am getting

<Invoice>
  <T>
    <TEST>
      <Title>1</Title>
    </TEST>
    <TEST>
      <Title>2</Title>
    </TEST>
  </T>
  <NAME>NN</NAME>
</Invoice>

And i want :


<Invoice>
    <TEST>
      <Title>1</Title>
    </TEST>
    <TEST>
      <Title>2</Title>
    </TEST>
  <NAME>NN</NAME>
</Invoice>
private void button1_Click(object sender, EventArgs e)
        {
            XMLTEST.TEST T1 = new TEST();
            T1.Title = "1";

            XMLTEST.TEST T2 = new TEST();
            T2.Title = "2";
            
            XmlTest myXML = new XmlTest();
            myXML.NAME = "NN";
            myXML.TEST=new List<TEST> { T1,T2};            
            TextWriter writer = new StreamWriter(@"C:\test.xml");        

            XmlSerializer serializer = new XmlSerializer(typeof(XmlTest));
            serializer.Serialize(writer, myXML);
            writer.Close();            
        }

                  
    }
    [XmlRoot("Invoice")]
    public class XmlTest
    {
        public string NAME
        { get; set; }
         
        public List<TEST> T;

   
      
    }
    public class TEST
    {
        public string Title
        { get; set; }
    }

Open in new window

0
Comment
Question by:WannabeNerd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 16

Accepted Solution

by:
kris_per earned 2000 total points
ID: 33724240

Add XmlElement attribute to the List member T like:

[XmlElement("TEST")]
public List<TEST> T;
0
 

Author Comment

by:WannabeNerd
ID: 33724456
Great Thanks for the help.

Only one thing :
I want it make it private so that it is serialized accordingly.

If its public it is on top of file which i want.


eg: NAME element before;

<Invoice>
  <NAME>NN</NAME>
    <TEST>
      <Title>1</Title>
    </TEST>
    <TEST>
      <Title>2</Title>
    </TEST>

</Invoice>
0
 

Author Comment

by:WannabeNerd
ID: 33724523
Never Mind Found it.
Just have to put

[XmlElement("TEST")] on  top :

private List<TEST> _T;


[XmlElement("TEST")]
public List<TEST> T
{
set....
get ....
}

0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question