Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

Browse by Tags · View All
SQL Server 119
#SQLServer 88
Oracle 70
#SQL SERVER 35
BRH 31
SQL Server 2012 29
denali 23
#TSQL 19
TSQL 19
C# 15

Archive · View All
October 2011 31
November 2011 30
September 2011 30
August 2011 18
December 2011 15
July 2011 13
June 2011 8
May 2012 4
April 2012 3
January 2010 3

Convert a generic List to XML file using XDocument

May 11 2012 12:00AM by Niladri Biswas   

Given a collection of Countries

India
Bangaladesh
Singapore
Hongkong

The expected output is to create an XML file whose structure will be as

<CountryInfo>
  <Countries>
    <Country Name="India" />
    <Country Name="Bangaladesh" />
    <Country Name="Singapore" />
    <Country Name="Hongkong" />
  </Countries>
</CountryInfo>

Here is my solution

var countryList = new List() { "India", "Bangaladesh", "Singapore", "Hongkong" };
XDocument doc =
				new XDocument
				(
					new XElement
					(
					 "CountryInfo", 
					 new XElement("Countries", countryList.Select(x => new XElement("Country", new XAttribute("Name", x))))
					)
				);
Console.WriteLine(doc.ToString());

Hope this will be helpful.

Tags: XDocument,Generic List To XML, C#


Niladri Biswas
7 · 21% · 6720
2
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

1  Comments  

  • really nice one

    commented on May 15 2012 7:50AM
    Kirti M.Darji
    10 · 16% · 5011

Your Comment


Sign Up or Login to post a comment.

"Convert a generic List to XML file using XDocument" rated 5 out of 5 by 2 readers
Convert a generic List to XML file using XDocument , 5.0 out of 5 based on 2 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]