设计一个XML文件,其中包含与国家相关的地区列表
本文关键字:国家 包含 列表 地区 文件 XML 一个 | 更新日期: 2023-09-27 18:10:49
我正在将国家名称和国家代码列表映射到如下所示的地区名称和地区代码列表。
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文件来存储这些国家和地区及其关联,以便我可以将一些c#数据控制绑定到该xml文件。
可以这样写:
<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;}
}