0

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

 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 文件。

4

1 回答 1

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;}
}
于 2013-04-24T04:36:42.443 回答