设计一个XML文件,其中包含与国家/地区关联的区域列表

时间:2013-04-24 04:28:44

标签: c# xml telerik radcombobox

我有一个国家/地区名称和国家/地区代码列表,映射到地区名称和地区代码列表,如下所示。

 Country and country codes


Country Long name
CA  Canada
US  United States
AF  Afghanistan
AG  Antigua and Barbuda
AI  Anguilla

Country  Region Description
CA  AB  Alberta
CH  AG  Aargau
CL  01  I - Iquique
CN  010 Beijing
CO  05  ANTIOQUIA
CZ  11  Praha
DE  01  Schleswig-Holstein
DK  001 Danish Capital Reg.
ES  01  Alava
FI  001 Ahvenanmaa
FR  01  Ain
GB  AB  Aberdeenshire

Country Region mapping

Country Province


   Canada   Alberta
                British Columbia
                Manitoba
                New Brunswick
                Newfoundland & Labr.
                Nova Scotia
                Northwest Terr.
                Nunavut
                Ontario
                Prince Edward Island
                Quebec
                Saskatchewan
                Yukon Territory
            USA Alaska
                Alabama
                Arkansas
                American Samoa
                Arizona
                California
                Colorado
                Connecticut
                District of Columbia
                Delaware
                Florida
                Georgia
                Guam
                Hawaii
                Iowa
                Idaho
                Illinois
                Indiana
                Kansas
                Kentucky
                Louisiana
                Massachusetts
                Maryland
                Maine
                Michigan
                Minnesota
                Missouri
                Northern Mariana Isl
                Mississippi
                Montana
                North Carolina
                North Dakota
                Nebraska
                New Hampshire
                New Jersey
                New Mexico
                Nevada
                New York
                Ohio
                Oklahoma
                Oregon
                Pennsylvania
                Puerto Rico
                Rhode Island
                South Carolina
                South Dakota
                Tennessee
                Texas
                Utah
                Virginia
                Virgin Islands
                Vermont
                Washington
                Wisconsin
                West Virginia
                Wyoming
                United States

如何设计xml文件以在这个xml文件中存储这些国家和地区及其关联,以便我可以将一些C#数据控件绑定到该xml文件。

1 个答案:

答案 0 :(得分:0)

也许是这样的:

<Countries>
    <Country LongName="Canada" ShortName="CA">
        <Provinces>
            <Province Name="Alberta"/>
            <Province Name="Manitoba"/>
        </Provinces>
    </Country>
    <Country LongName="United States"  ShortName="US">
        <Provinces>
            <Province Name="Alaska"/>
            <Province Name="Alabama"/>
        </Provinces>
    </Country>
</Countries>

您需要一个适当的数据结构来将XML序列化。 并将数据对象绑定到控件

public class Province
{
    public string Name {get;set}
}

public class Country
{
    public string ShortName {get;set}
    public string LongName {get;set}
    public List<Province> Provinces {get;set}
}

public class UIObject
{
    public List<Country> Countries {get;set;}
}